
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>logback中文网|第三章：logback 的配置</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="logback中文网包含了logback中文文档，最新资讯，应用案例等。logback 继承自 log4j，它建立在有十年工业经验的日志系统之上。它比其它所有的日志系统更快并且更小，包含了许多独特并且有用的特性。"><meta name="keywords" content="logback中文文档, logback api文档, logback log4j,springboot logback,logback日志类型">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="04第四章Appenders.html" />
    
    
    <link rel="prev" href="02第二章架构.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="01第一章logback介绍.html">
            
                <a href="01第一章logback介绍.html">
            
                    
                    第一章：logback 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="02第二章架构.html">
            
                <a href="02第二章架构.html">
            
                    
                    第二章：架构
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4" data-path="03第三章logback的配置.html">
            
                <a href="03第三章logback的配置.html">
            
                    
                    第三章：logback 的配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="04第四章Appenders.html">
            
                <a href="04第四章Appenders.html">
            
                    
                    第四章：Appenders
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="05第五章Encoder.html">
            
                <a href="05第五章Encoder.html">
            
                    
                    第五章：Encoder
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="06第六章Layouts.html">
            
                <a href="06第六章Layouts.html">
            
                    
                    第六章：Layouts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="07第七章Filters.html">
            
                <a href="07第七章Filters.html">
            
                    
                    第七章：Filters
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="08第八章MDC.html">
            
                <a href="08第八章MDC.html">
            
                    
                    第八章：MDC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="09第九章日志隔离.html">
            
                <a href="09第九章日志隔离.html">
            
                    
                    第九章：日志隔离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="10第十章JMX配置器.html">
            
                <a href="10第十章JMX配置器.html">
            
                    
                    第十章：JMX 配置器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="11第十一章Joran.html">
            
                <a href="11第十一章Joran.html">
            
                    
                    第十一章：Joran
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="12第十二章Groovy配置.html">
            
                <a href="12第十二章Groovy配置.html">
            
                    
                    第十二章：Groovy 配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="13第十三章从log4j迁移.html">
            
                <a href="13第十三章从log4j迁移.html">
            
                    
                    第十三章：从 log4j 迁移
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="14第十四章Receivers.html">
            
                <a href="14第十四章Receivers.html">
            
                    
                    第十四章：Receivers
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="15第十五章使用SSL.html">
            
                <a href="15第十五章使用SSL.html">
            
                    
                    第十五章：使用 SSL
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >第三章：logback 的配置</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x6211;&#x4EEC;&#x5F00;&#x59CB;&#x901A;&#x8FC7;&#x591A;&#x79CD;&#x914D;&#x7F6E; logback&#xFF0C;&#x4EE5;&#x53CA;&#x8BB8;&#x591A;&#x793A;&#x4F8B;&#x7684;&#x914D;&#x7F6E;&#x811A;&#x672C;&#x3002;logback &#x4F9D;&#x8D56;&#x7684;&#x914D;&#x7F6E;&#x6846;&#x67B6; - <a href="#Joran">Joran</a> &#x5C06;&#x4F1A;&#x5728;&#x4E4B;&#x540E;&#x7684;&#x7AE0;&#x8282;&#x4ECB;&#x7ECD;</p>
<h2 id="&#x914D;&#x7F6E;-logback">&#x914D;&#x7F6E; logback</h2>
<p>&#x5728;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x5F53;&#x4E2D;&#x4F7F;&#x7528;&#x65E5;&#x5FD7;&#x8BED;&#x53E5;&#x9700;&#x8981;&#x8017;&#x8D39;&#x5927;&#x91CF;&#x7684;&#x7CBE;&#x529B;&#x3002;&#x6839;&#x636E;&#x8C03;&#x67E5;&#xFF0C;&#x5927;&#x7EA6;&#x6709;&#x767E;&#x5206;&#x4E4B;&#x56DB;&#x7684;&#x4EE3;&#x7801;&#x7528;&#x4E8E;&#x6253;&#x5370;&#x65E5;&#x5FD7;&#x3002;&#x5373;&#x4F7F;&#x5728;&#x4E00;&#x4E2A;&#x4E2D;&#x578B;&#x5E94;&#x7528;&#x7684;&#x4EE3;&#x7801;&#x5F53;&#x4E2D;&#x4E5F;&#x6709;&#x6210;&#x5343;&#x4E0A;&#x4E07;&#x6761;&#x65E5;&#x5FD7;&#x7684;&#x6253;&#x5370;&#x8BED;&#x53E5;&#x3002;&#x8003;&#x8651;&#x5230;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x5DE5;&#x5177;&#x6765;&#x7BA1;&#x7406;&#x8FD9;&#x4E9B;&#x65E5;&#x5FD7;&#x8BED;&#x53E5;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7F16;&#x7A0B;&#x6216;&#x8005;&#x914D;&#x7F6E; XML &#x811A;&#x672C;&#x6216;&#x8005; Groovy &#x683C;&#x5F0F;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x914D;&#x7F6E; logback&#x3002;&#x5BF9;&#x4E8E;&#x5DF2;&#x7ECF;&#x4F7F;&#x7528; log4j &#x7684;&#x7528;&#x6237;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;<a href="https://logback.qos.ch/translator/" target="_blank">&#x5DE5;&#x5177;</a>&#x6765;&#x628A; log4j.properties &#x8F6C;&#x6362;&#x4E3A; logback.xml&#x3002;</p>
<p>&#x4EE5;&#x4E0B;&#x662F; logback &#x7684;&#x521D;&#x59CB;&#x5316;&#x6B65;&#x9AA4;&#xFF1A;</p>
<ol>
<li>logback &#x4F1A;&#x5728;&#x7C7B;&#x8DEF;&#x5F84;&#x4E0B;&#x5BFB;&#x627E;&#x540D;&#x4E3A; logback-test.xml &#x7684;&#x6587;&#x4EF6;&#x3002;</li>
<li>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#xFF0C;logback &#x4F1A;&#x7EE7;&#x7EED;&#x5BFB;&#x627E;&#x540D;&#x4E3A; logback.groovy &#x7684;&#x6587;&#x4EF6;&#x3002;</li>
<li>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#xFF0C;logback &#x4F1A;&#x7EE7;&#x7EED;&#x5BFB;&#x627E;&#x540D;&#x4E3A; logback.xml &#x7684;&#x6587;&#x4EF6;&#x3002;</li>
<li>&#x5982;&#x679C;&#x6CA1;&#x6709;&#x627E;&#x5230;&#xFF0C;&#x5C06;&#x4F1A;&#x901A;&#x8FC7; JDK &#x63D0;&#x4F9B;&#x7684; <a href="https://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html" target="_blank">ServiceLoader</a> &#x5DE5;&#x5177;&#x5728;&#x7C7B;&#x8DEF;&#x5F84;&#x4E0B;&#x5BFB;&#x627E;&#x6587;&#x4EF6; <em>META-INFO/services/ch.qos.logback.classic.spi.Configurator</em>&#xFF0C;&#x8BE5;&#x6587;&#x4EF6;&#x7684;&#x5185;&#x5BB9;&#x4E3A;&#x5B9E;&#x73B0;&#x4E86; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/spi/Configurator.html" target="_blank"><code>Configurator</code></a> &#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#x7684;&#x5168;&#x9650;&#x5B9A;&#x7C7B;&#x540D;&#x3002;</li>
<li>&#x5982;&#x679C;&#x4EE5;&#x4E0A;&#x90FD;&#x6CA1;&#x6709;&#x6210;&#x529F;&#xFF0C;logback &#x4F1A;&#x901A;&#x8FC7; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/BasicConfigurator.html" target="_blank">BasicConfigurator</a> &#x4E3A;&#x81EA;&#x5DF1;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF0C;&#x5E76;&#x4E14;&#x65E5;&#x5FD7;&#x5C06;&#x4F1A;&#x5168;&#x90E8;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x51FA;&#x6765;&#x3002;</li>
</ol>
<p>&#x6700;&#x540E;&#x4E00;&#x6B65;&#x7684;&#x76EE;&#x7684;&#x662F;&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;&#x5728;&#x6240;&#x6709;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x90FD;&#x6CA1;&#x6709;&#x88AB;&#x627E;&#x5230;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x7684;&#xFF08;&#x4F46;&#x662F;&#x662F;&#x975E;&#x5E38;&#x57FA;&#x7840;&#x7684;&#xFF09;&#x914D;&#x7F6E;&#x3002;</p>
<p>&#x5982;&#x679C;&#x4F60;&#x4F7F;&#x7528;&#x7684;&#x662F; maven&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x5728; <em>src/test/resources</em> &#x4E0B;&#x65B0;&#x5EFA; logback-test.xml&#x3002;maven &#x4F1A;&#x786E;&#x4FDD;&#x5B83;&#x4E0D;&#x4F1A;&#x88AB;&#x751F;&#x6210;&#x3002;&#x6240;&#x4EE5;&#x4F60;&#x53EF;&#x4EE5;&#x5728;&#x6D4B;&#x8BD5;&#x73AF;&#x5883;&#x4E2D;&#x7ED9;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x547D;&#x540D;&#x4E3A; <em>logback-test.xml</em>&#xFF0C;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E2D;&#x547D;&#x540D;&#x4E3A; <em>logback.xml</em>&#x3002;</p>
<p><code>FAST START-UP</code> Joran &#x89E3;&#x6790;&#x7ED9;&#x5B9A;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5927;&#x6982;&#x9700;&#x8981;&#x8017;&#x8D39; 100 &#x6BEB;&#x79D2;&#x3002;&#x4E3A;&#x4E86;&#x51CF;&#x5C11;&#x542F;&#x52A8;&#x7684;&#x4E16;&#x95F4;&#x5B89;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x4F7F;&#x7528; <a href="https://docs.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html" target="_blank">ServiceLoader</a> &#x6765;&#x52A0;&#x8F7D;&#x81EA;&#x5B9A;&#x4E49;&#x7684; <code>Configurator</code>&#xFF0C;&#x5E76;&#x4F7F;&#x7528; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/BasicConfigurator.html" target="_blank">BasicConfigurator</a> &#x4F5C;&#x4E3A;&#x4E00;&#x4E2A;&#x597D;&#x7684;&#x8D77;&#x70B9;&#xFF08;&#x4E2A;&#x4EBA;&#x7684;&#x7406;&#x89E3;&#x662F;&#x901A;&#x8FC7;&#x7EE7;&#x627F;&#x8FD9;&#x4E2A;&#x7C7B;&#xFF09;&#x3002;</p>
<h3 id="&#x81EA;&#x52A8;&#x914D;&#x7F6E;-logback">&#x81EA;&#x52A8;&#x914D;&#x7F6E; logback</h3>
<p>&#x6700;&#x7B80;&#x5355;&#x7684;&#x65B9;&#x5F0F;&#x914D;&#x7F6E; logback &#x662F;&#x8BA9;&#x5B83;&#x53BB;&#x52A0;&#x8F7D;&#x9ED8;&#x8BA4;&#x7684;&#x914D;&#x7F6E;&#x3002;&#x4F8B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> chapters.configuration;

<span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp1</span> </span>{

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger LOGGER = LoggerFactory.getLogger(MyApp1.class);

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        LOGGER.info(<span class="hljs-string">&quot;Entering application.&quot;</span>);

        Foo foo = <span class="hljs-keyword">new</span> Foo();
        foo.doIt();
        LOGGER.info(<span class="hljs-string">&quot;Exiting application.&quot;</span>);
    }   
}
</code></pre>
<p><code>Foo</code> &#x7684;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-jav">package chapters.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Foo {

    public static final Logger LOGGER = LoggerFactory.getLogger(Foo.class);

    public void doIt() {
        LOGGER.debug(&quot;Did it again!&quot;);
    }
}
</code></pre>
<p>&#x5047;&#x8BBE;&#x914D;&#x7F6E;&#x6587;&#x4EF6; <em>logback-test.xml</em> &#x6216;&#x8005; <em>logback.xml</em> &#x4E0D;&#x5B58;&#x5728;&#xFF0C;logback &#x4F1A;&#x8C03;&#x7528; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/BasicConfigurator.html" target="_blank">BasicConfigurator</a> &#x8FDB;&#x884C;&#x6700;&#x5C0F;&#x7684;&#x914D;&#x7F6E;&#x3002;&#x6700;&#x5C0F;&#x7684;&#x914D;&#x7F6E;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x9644;&#x52A0;&#x5230; root logger &#x4E0A;&#x7684; <code>ConsoleAppender</code>&#xFF0C;&#x683C;&#x5F0F;&#x5316;&#x8F93;&#x51FA;&#x4F7F;&#x7528; <code>PatternLayoutEncoder</code> &#x5BF9;&#x6A21;&#x7248; <em>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</em> &#x8FDB;&#x884C;&#x683C;&#x5F0F;&#x5316;&#x3002;root logger &#x9ED8;&#x8BA4;&#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x4E3A; <code>DEBUG</code>&#x3002;</p>
<p>&#x6240;&#x4EE5;&#xFF0C;<em>MyApp1</em> &#x7684;&#x8F93;&#x51FA;&#x4FE1;&#x606F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">16</span>:<span class="hljs-number">59</span>:<span class="hljs-number">20.161</span> [main] INFO chapters.configuration.MyApp1 - Entering application.
<span class="hljs-number">16</span>:<span class="hljs-number">59</span>:<span class="hljs-number">20.164</span> [main] DEBUG chapters.configuration.Foo - Did it again!
<span class="hljs-number">16</span>:<span class="hljs-number">59</span>:<span class="hljs-number">20.164</span> [main] INFO chapters.configuration.MyApp1 - Exiting application.
</code></pre>
<p><code>MyApp1</code>  &#x901A;&#x8FC7;&#x8C03;&#x7528; <code>org.slf4j.LoggerFactory</code> &#x4E0E; <code>org.slf4j.Logger</code> &#x8FD9;&#x4E24;&#x4E2A;&#x7C7B;&#x4E0E; logback &#x76F8;&#x5173;&#x8054;&#xFF0C;&#x5E76;&#x68C0;&#x7D22;&#x4F1A;&#x7528;&#x5230;&#x7684; logger&#x3002;&#x9664;&#x4E86;&#x914D;&#x7F6E; logback &#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x5BA2;&#x6237;&#x7AEF;&#x7684;&#x4EE3;&#x7801;&#x4E0D;&#x9700;&#x8981;&#x4F9D;&#x8D56; logback&#xFF0C;&#x56E0;&#x4E3A; SLF4J &#x5141;&#x8BB8;&#x5728;&#x5B83;&#x7684;&#x62BD;&#x8C61;&#x5C42;&#x4E0B;&#x4F7F;&#x7528;&#x4EFB;&#x4F55;&#x65E5;&#x5FD7;&#x6846;&#x67B6;&#xFF0C;&#x6240;&#x4EE5;&#x975E;&#x5E38;&#x5BB9;&#x6613;&#x5C06;&#x5927;&#x91CF;&#x4EE3;&#x7801;&#x4ECE;&#x4E00;&#x4E2A;&#x6846;&#x67B6;&#x8FC1;&#x79FB;&#x5230;&#x53E6;&#x4E00;&#x4E2A;&#x6846;&#x67B6;&#x3002;</p>
<h3 id="&#x4F7F;&#x7528;-logback-testxml-&#x6216;-logbackxml-&#x81EA;&#x52A8;&#x914D;&#x7F6E;">&#x4F7F;&#x7528; <em>logback-test.xml</em> &#x6216; <em>logback.xml</em> &#x81EA;&#x52A8;&#x914D;&#x7F6E;</h3>
<p>&#x4E0B;&#x9762;&#x7684;&#x914D;&#x7F6E;&#x7B49;&#x540C;&#x4E8E;&#x901A;&#x8FC7; <code>BasicConfigurator</code> &#x8FDB;&#x884C;&#x914D;&#x7F6E;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span> 
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<blockquote>
<p>&#x4F60;&#x9700;&#x8981;&#x5C06;&#x4E0A;&#x9762;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x547D;&#x540D;&#x4E3A; logback.xml &#x6216; logback-test.xml</p>
</blockquote>
<p>&#x8FD0;&#x884C; <em>MyApp1</em>&#xFF0C;&#x4F60;&#x5C06;&#x4F1A;&#x770B;&#x5230;&#x76F8;&#x540C;&#x7684;&#x7ED3;&#x679C;&#xFF08;&#x4F60;&#x8981;&#x662F;&#x4E0D;&#x76F8;&#x4FE1;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x66F4;&#x6539;&#x6A21;&#x7248;&#xFF0C;&#x770B;&#x662F;&#x5426;&#x751F;&#x6548;&#xFF09;&#x3002;</p>
<h4 id="&#x5728;&#x8B66;&#x544A;&#x6216;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x81EA;&#x52A8;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;">&#x5728;&#x8B66;&#x544A;&#x6216;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x81EA;&#x52A8;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;</h4>
<p>&#x5982;&#x679C;&#x5728;&#x89E3;&#x6790;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x8FC7;&#x7A0B;&#x5F53;&#x4E2D;&#x53D1;&#x751F;&#x4E86;&#x9519;&#x8BEF;&#xFF0C;logback &#x4F1A;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x51FA;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x6570;&#x636E;&#x3002;&#x5982;&#x679C;&#x7528;&#x6237;&#x660E;&#x786E;&#x7684;&#x5B9A;&#x4E49;&#x4E86;&#x72B6;&#x6001;&#x76D1;&#x542C;&#x5668;&#xFF0C;&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x91CD;&#x590D;&#xFF0C;logback &#x5C06;&#x4E0D;&#x4F1A;&#x81EA;&#x52A8;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;</p>
<p>&#x5728;&#x6CA1;&#x6709;&#x8B66;&#x544A;&#x6216;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x60F3;&#x67E5;&#x770B; logback &#x5185;&#x90E8;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>StatusPrinter</code> &#x7C7B;&#x6765;&#x8C03;&#x7528; <code>print()</code> &#x65B9;&#x6CD5;&#x67E5;&#x770B;&#x5177;&#x4F53;&#x7684;&#x4FE1;&#x606F;&#x3002;</p>
<blockquote>
<p>&#x5728; <em>MyApp1</em> &#x7684;&#x57FA;&#x7840;&#x4E0A;&#x6DFB;&#x52A0;&#x4E24;&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x5E76;&#x547D;&#x540D;&#x4E3A; <em>MyApp2</em></p>
</blockquote>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> chapters.configuration;

<span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;

<span class="hljs-keyword">import</span> ch.qos.logback.classic.LoggerContext;
<span class="hljs-keyword">import</span> ch.qos.logback.core.util.StatusPrinter;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp2</span> </span>{

    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger LOGGER = LoggerFactory.getLogger(MyApp2.class);

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
        StatusPrinter.print(lc);

        LOGGER.info(<span class="hljs-string">&quot;Entering application.&quot;</span>);

        Foo foo = <span class="hljs-keyword">new</span> Foo();
        foo.doIt();
        LOGGER.info(<span class="hljs-string">&quot;Exiting application.&quot;</span>);
    }
}
</code></pre>
<p>&#x8F93;&#x51FA;&#x4FE1;&#x606F;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">130</span> |-INFO in ch.qos.logback.classic.LoggerContext[<span class="hljs-keyword">default</span>] - Could NOT find resource [logback-test.xml]
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">130</span> |-INFO in ch.qos.logback.classic.LoggerContext[<span class="hljs-keyword">default</span>] - Could NOT find resource [logback.groovy]
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">131</span> |-INFO in ch.qos.logback.classic.LoggerContext[<span class="hljs-keyword">default</span>] - Found resource [logback.xml] at [file:/D:/E/project/logback-examples/target/classes/logback.xml]
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">224</span> |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">225</span> |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">238</span> |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">251</span> |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming <span class="hljs-keyword">default</span> type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] <span class="hljs-keyword">for</span> [encoder] property
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">328</span> |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">329</span> |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">329</span> |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47</span>,<span class="hljs-number">332</span> |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@<span class="hljs-number">7</span>d4793a8 - Registering current configuration as safe fallback point

<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47.340</span> [main] INFO  chapters.configuration.MyApp2 - Entering application.
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47.342</span> [main] DEBUG chapters.configuration.Foo - Did it again!
<span class="hljs-number">17</span>:<span class="hljs-number">56</span>:<span class="hljs-number">47.342</span> [main] INFO  chapters.configuration.MyApp2 - Exiting application.
</code></pre>
<p>&#x5728;&#x8F93;&#x51FA;&#x4FE1;&#x606F;&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x6E05;&#x695A;&#x7684;&#x770B;&#x5230;&#x5185;&#x90E8;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF0C;&#x53C8;&#x79F0;&#x4E4B;&#x4E3A; <code>Status</code> &#x5BF9;&#x8C61;&#xFF0C;&#x53EF;&#x4EE5;&#x5F88;&#x65B9;&#x4FBF;&#x7684;&#x83B7;&#x53D6; logback &#x7684;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x3002;</p>
<h4 id="&#x72B6;&#x6001;&#x6570;&#x636E;">&#x72B6;&#x6001;&#x6570;&#x636E;</h4>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x6784;&#x9020;&#x4E00;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6765;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF0C;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x7F16;&#x7801;&#x7684;&#x65B9;&#x5F0F;&#x8C03;&#x7528; <code>StatusPrinter</code> &#x53BB;&#x5B9E;&#x73B0;&#x3002;&#x53EA;&#x9700;&#x8981;&#x5728; <em>configuration</em> &#x5143;&#x7D20;&#x4E0A;&#x6DFB;&#x52A0; <em>debug</em> &#x5C5E;&#x6027;&#x3002;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5982;&#x4E0B;&#x6240;&#x793A;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;debug &#x5C5E;&#x6027;&#x53EA;&#x8DDF;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x6709;&#x5173;&#xFF0C;&#x5E76;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD; logback &#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x4E5F;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD; logger &#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x3002;</p>
</blockquote>
<p><em>Example: sample1.xml</em></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<blockquote>
<p>&#x9700;&#x8981;&#x5C06; sample1.xml &#x6539;&#x540D;&#x4E3A; logback.xml &#x6216; logback-test.xml&#xFF0C;&#x4E0D;&#x7136; logbak &#x627E;&#x4E0D;&#x5230;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;&#x4EE5;&#x540E;&#x8FD9;&#x79CD;&#x60C5;&#x51B5;&#x4E0D;&#x518D;&#x91CD;&#x590D;&#x7533;&#x660E;&#x3002;</p>
</blockquote>
<p>&#x5982;&#x679C;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x914D;&#x7F6E;&#x6709;&#x95EE;&#x9898;&#xFF0C;logback &#x4F1A;&#x68C0;&#x6D4B;&#x5230;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#x5E76;&#x4E14;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x5982;&#x679C;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6CA1;&#x6709;&#x88AB;&#x627E;&#x5230;&#xFF0C;logback &#x4E0D;&#x4F1A;&#x6253;&#x5370;&#x5B83;&#x7684;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF0C;&#x56E0;&#x4E3A;&#x6CA1;&#x6709;&#x68C0;&#x6D4B;&#x5230;&#x9519;&#x8BEF;&#x3002;&#x901A;&#x8FC7;&#x7F16;&#x7801;&#x65B9;&#x5F0F;&#x8C03;&#x7528; <code>StatusPrinter.print()</code> &#x65B9;&#x6CD5;&#x4F1A;&#x5728;&#x4EFB;&#x4F55;&#x60C5;&#x51B5;&#x4E0B;&#x90FD;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;</p>
<p><code>&#x5F3A;&#x5236;&#x8F93;&#x51FA;&#x72B6;&#x6001;&#x4FE1;&#x606F;</code>&#xFF1A;&#x5728;&#x7F3A;&#x4E4F;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x8981;&#x627E;&#x4E00;&#x4E2A;&#x6709;&#x95EE;&#x9898;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5F88;&#x96BE;&#xFF0C;&#x7279;&#x522B;&#x662F;&#x5728;&#x751F;&#x4EA7;&#x73AF;&#x5883;&#x4E0B;&#x3002;&#x4E3A;&#x4E86;&#x80FD;&#x591F;&#x66F4;&#x597D;&#x7684;&#x5B9A;&#x4F4D;&#x5230;&#x6709;&#x95EE;&#x9898;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027; &quot;<a href="#%22logback.statusListenerClass%22%20system%20property">logback.statusListenerClass</a>&quot; &#x6765;&#x8BBE;&#x7F6E; <code>StatusListener</code> &#x5F3A;&#x5236;&#x8F93;&#x51FA;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027; &quot;logback.statusListenerClass&quot; &#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x5728;&#x9047;&#x5230;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x8FDB;&#x884C;&#x8F93;&#x51FA;&#x3002;</p>
<p>&#x8BBE;&#x7F6E; <code>debug=&quot;true&quot;</code> &#x5B8C;&#x5168;&#x7B49;&#x540C;&#x4E8E;&#x914D;&#x7F6E;&#x4E00;&#x4E2A; <code>OnConsoleStatusListener</code> &#x3002;&#x5177;&#x4F53;&#x793A;&#x4F8B;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><em>Example: onConsoleStatusListener.xml</em></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">statusListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.status.OnConsoleStatusListener&quot;</span> /&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x5269;&#x4E0B;&#x7684;&#x914D;&#x7F6E;&#x8DDF;&#x4E4B;&#x524D;&#x7684;&#x76F8;&#x540C; --&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8BBE;&#x7F6E; <code>debug=&quot;true&quot;</code> &#x4E0E;&#x914D;&#x7F6E; <code>OnConsoleStatusListener</code> &#x7684;&#x6548;&#x679C;&#x5B8C;&#x5168;&#x4E00;&#x6837;&#x3002;</p>
<h3 id="&#x901A;&#x8FC7;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;">&#x901A;&#x8FC7;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;</h3>
<p>&#x901A;&#x8FC7;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027; <code>logback.configurationFile</code> &#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x9ED8;&#x8BA4;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x3002;&#x5B83;&#x7684;&#x503C;&#x53EF;&#x4EE5;&#x662F; URL&#xFF0C;&#x7C7B;&#x8DEF;&#x5F84;&#x4E0B;&#x7684;&#x6587;&#x4EF6;&#x6216;&#x8005;&#x662F;&#x5E94;&#x7528;&#x5916;&#x90E8;&#x7684;&#x6587;&#x4EF6;&#x3002;</p>
<pre><code class="lang-java">java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x6587;&#x4EF6;&#x7C7B;&#x578B;&#x53EA;&#x80FD;&#x662F; &quot;.xml&quot; &#x6216;&#x8005; &quot;.groovy&quot;&#xFF0C;&#x5176;&#x5B83;&#x7684;&#x62D3;&#x5C55;&#x6587;&#x4EF6;&#x5C06;&#x4F1A;&#x88AB;&#x5FFD;&#x7565;&#x3002;</p>
</blockquote>
<p>&#x56E0;&#x4E3A; <code>logback.configureFile</code> &#x662F;&#x4E00;&#x4E2A;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#xFF0C;&#x6240;&#x4EE5;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x5E94;&#x7528;&#x5185;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#x3002;&#x4F46;&#x662F;&#x5FC5;&#x987B;&#x5728; logger &#x5B9E;&#x4F8B;&#x521B;&#x5EFA;&#x524D;&#x8FDB;&#x884C;&#x8BBE;&#x7F6E;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;

<span class="hljs-keyword">import</span> ch.qos.logback.classic.util.ContextInitializer;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ServerMain</span> </span>{

    <span class="hljs-keyword">static</span> {
        System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, <span class="hljs-string">&quot;configurationFile.xml&quot;</span>);
    }

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger LOGGER = LoggerFactory.getLogger(ServerMain.class);

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{
        LOGGER.info(<span class="hljs-string">&quot;xxxxxxxx&quot;</span>);
    }
}
</code></pre>
<h3 id="&#x5F53;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x66F4;&#x6539;&#x65F6;&#xFF0C;&#x81EA;&#x52A8;&#x52A0;&#x8F7D;">&#x5F53;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x66F4;&#x6539;&#x65F6;&#xFF0C;&#x81EA;&#x52A8;&#x52A0;&#x8F7D;</h3>
<p>&#x4E3A;&#x4E86;&#x8BA9; logback &#x80FD;&#x591F;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6539;&#x53D8;&#x7684;&#x65F6;&#x5019;&#x81EA;&#x52A8;&#x53BB;&#x626B;&#x63CF;&#xFF0C;&#x9700;&#x8981;&#x5728; <code>&lt;configuration&gt;</code> &#x6807;&#x7B7E;&#x4E0A;&#x6DFB;&#x52A0; <code>scan=true</code> &#x5C5E;&#x6027;&#x3002;</p>
<p><em>Example</em></p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">scan</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
    ...
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x4E00;&#x5206;&#x949F;&#x626B;&#x63CF;&#x4E00;&#x6B21;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x770B;&#x662F;&#x5426;&#x6709;&#x66F4;&#x6539;&#x3002;&#x901A;&#x8FC7; <code>&lt;configuration&gt;</code> &#x6807;&#x7B7E;&#x4E0A;&#x7684; <code>scanPeriod</code> &#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x626B;&#x63CF;&#x5468;&#x671F;&#x3002;&#x626B;&#x63CF;&#x5468;&#x671F;&#x7684;&#x65F6;&#x95F4;&#x5355;&#x4F4D;&#x53EF;&#x4EE5;&#x662F;&#x6BEB;&#x79D2;&#x3001;&#x79D2;&#x3001;&#x5206;&#x949F;&#x6216;&#x8005;&#x5C0F;&#x65F6;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-xml">&lt;configuration scan=&quot;true&quot; scanPeriod=&quot;30 seconds&quot;
   ...
&lt;/configuration&gt;
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#x65F6;&#x95F4;&#x5355;&#x4F4D;&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x4E3A;&#x6BEB;&#x79D2;&#x3002;</p>
</blockquote>
<p>&#x5F53;&#x8BBE;&#x7F6E;&#x4E86; <code>scan=&quot;true&quot;</code>&#xFF0C;&#x4F1A;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A; <a href="#https://logback.qos.ch/xref/ch/qos/logback/classic/joran/ReconfigureOnChangeTask.html">ReconfigureOnChangeTask</a> &#x4EFB;&#x52A1;&#x7528;&#x4E8E;&#x76D1;&#x89C6;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x53D8;&#x5316;&#x3002;<code>ReconfigureOnChangeTask</code> &#x4E5F;&#x4F1A;&#x81EA;&#x52A8;&#x76D1;&#x89C6;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x7684;&#x53D8;&#x5316;&#x3002;</p>
<p>&#x5982;&#x679C;&#x66F4;&#x6539;&#x540E;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6709;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;&#xFF0C;&#x5219;&#x4F1A;&#x56DE;&#x9000;&#x5230;&#x4E4B;&#x524D;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;</p>
<h4 id="&#x5728;&#x5806;&#x6808;&#x4E2D;&#x5C55;&#x793A;&#x5305;&#x6570;&#x636E;">&#x5728;&#x5806;&#x6808;&#x4E2D;&#x5C55;&#x793A;&#x5305;&#x6570;&#x636E;</h4>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5728; 1.1.4 &#x7248;&#x672C;&#x4E2D;&#xFF0C;&#x5C55;&#x793A;&#x5305;&#x6570;&#x636E;&#x662F;&#x9ED8;&#x8BA4;&#x88AB;&#x7981;&#x7528;&#x7684;&#x3002;</p>
</blockquote>
<p>&#x5982;&#x679C;&#x542F;&#x7528;&#x4E86;&#x5C55;&#x793A;&#x5305;&#x6570;&#x636E;&#xFF0C;logback &#x4F1A;&#x5728;&#x5806;&#x6808;&#x7684;&#x6BCF;&#x4E00;&#x884C;&#x663E;&#x793A; jar &#x5305;&#x7684;&#x540D;&#x5B57;&#x4EE5;&#x53CA; jar &#x7684;&#x7248;&#x672C;&#x53F7;&#x3002;&#x5C55;&#x793A;&#x5305;&#x6570;&#x636E;&#x53EF;&#x4EE5;&#x5F88;&#x597D;&#x7684;&#x89E3;&#x51B3; jar &#x7248;&#x672C;&#x51B2;&#x7A81;&#x7684;&#x95EE;&#x9898;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8FD9;&#x4E2A;&#x7684;&#x4EE3;&#x4EF7;&#x6BD4;&#x8F83;&#x9AD8;&#xFF0C;&#x7279;&#x522B;&#x662F;&#x5728;&#x9891;&#x7E41;&#x62A5;&#x9519;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x3002;</p>
<p><code>Example</code>&#xFF1A;</p>
<pre><code class="lang-txt">14:28:48.835 [btpool0-7] INFO  c.q.l.demo.prime.PrimeAction - 99 is not a valid value
java.lang.Exception: 99 is invalid
  at ch.qos.logback.demo.prime.PrimeAction.execute(PrimeAction.java:28) [classes/:na]
  at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431) [struts-1.2.9.jar:1.2.9]
  at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236) [struts-1.2.9.jar:1.2.9]
  at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) [struts-1.2.9.jar:1.2.9]
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:820) [servlet-api-2.5-6.1.12.jar:6.1.12]
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:502) [jetty-6.1.12.jar:6.1.12]
  at ch.qos.logback.demo.UserServletFilter.doFilter(UserServletFilter.java:44) [classes/:na]
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1115) [jetty-6.1.12.jar:6.1.12]
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:361) [jetty-6.1.12.jar:6.1.12]
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:417) [jetty-6.1.12.jar:6.1.12]
  at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230) [jetty-6.1.12.jar:6.1.12]
</code></pre>
<p>&#x542F;&#x7528;&#x5C55;&#x793A;&#x5305;&#x6570;&#x636E;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">packagingData</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
    ...
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="&#x76F4;&#x63A5;&#x8C03;&#x7528;-joranconfigurator">&#x76F4;&#x63A5;&#x8C03;&#x7528; <code>JoranConfigurator</code></h3>
<p>Logback &#x4F9D;&#x8D56;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5E93;&#x4E3A; Joran&#xFF0C;&#x662F; logback-core &#x7684;&#x4E00;&#x90E8;&#x5206;&#x3002;logback &#x7684;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#x673A;&#x5236;&#x4E3A;&#xFF1A;&#x901A;&#x8FC7; <code>JoranConfigurator</code> &#x5728;&#x7C7B;&#x8DEF;&#x5F84;&#x4E0A;&#x5BFB;&#x627E;&#x9ED8;&#x8BA4;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x76F4;&#x63A5;&#x8C03;&#x7528; <code>JoranConfigurator</code> &#x7684;&#x65B9;&#x5F0F;&#x6765;&#x91CD;&#x5199; logback &#x7684;&#x9ED8;&#x8BA4;&#x914D;&#x7F6E;&#x673A;&#x5236;&#x3002;</p>
<p><code>Example</code>&#xFF1A;&#x76F4;&#x63A5;&#x8C03;&#x7528; <code>JoranConfigurator</code></p>
<pre><code class="lang-java"><span class="hljs-keyword">package</span> chapters.configuration;

<span class="hljs-keyword">import</span> org.slf4j.Logger;
<span class="hljs-keyword">import</span> org.slf4j.LoggerFactory;

<span class="hljs-keyword">import</span> ch.qos.logback.access.joran.JoranConfigurator;
<span class="hljs-keyword">import</span> ch.qos.logback.classic.LoggerContext;
<span class="hljs-keyword">import</span> ch.qos.logback.core.joran.spi.JoranException;
<span class="hljs-keyword">import</span> ch.qos.logback.core.util.StatusPrinter;

<span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyApp3</span> </span>{

    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">final</span> Logger LOGGER = LoggerFactory.getLogger(MyApp3.class);

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory();
        JoranConfigurator joranConfigurator = <span class="hljs-keyword">new</span> JoranConfigurator();
        joranConfigurator.setContext(context);
        context.reset();
        <span class="hljs-keyword">try</span> {
            joranConfigurator.doConfigure(args[<span class="hljs-number">0</span>]);
        } <span class="hljs-keyword">catch</span> (JoranException e) {
            e.printStackTrace();
        }

        StatusPrinter.printInCaseOfErrorsOrWarnings(context);

        LOGGER.info(<span class="hljs-string">&quot;Entering application&quot;</span>);

        Foo foo = <span class="hljs-keyword">new</span> Foo();
        foo.doIt();
        LOGGER.info(<span class="hljs-string">&quot;Exiting application&quot;</span>);
    }
}
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5BF9;&#x4E8E;&#x591A;&#x4E2A;&#x6B65;&#x9AA4;&#x7684;&#x914D;&#x7F6E;&#xFF0C;<code>context.reset()</code> &#x4E0D;&#x9700;&#x8981;&#x8C03;&#x7528;&#xFF08;&#x4E0D;&#x662F;&#x5F88;&#x7406;&#x89E3;&#x8FD9;&#x53E5;&#x8BDD;&#x7684;&#x610F;&#x601D;&#xFF09;&#x3002;</p>
</blockquote>
<h3 id="&#x67E5;&#x770B;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x4FE1;&#x606F;">&#x67E5;&#x770B;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x4FE1;&#x606F;</h3>
<p>logback &#x901A;&#x8FC7; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/status/StatusManager.html" target="_blank">StatusManager</a> &#x7684;&#x5BF9;&#x8C61;&#x6765;&#x6536;&#x96C6;&#x5185;&#x90E8;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#xFF0C;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>LoggerContext</code> &#x6765;&#x83B7;&#x53D6;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x4E00;&#x4E2A;&#x7ED9;&#x5B9A;&#x7684; <code>StatusManager</code>&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x83B7;&#x53D6; logback &#x4E0A;&#x4E0B;&#x6587;&#x6240;&#x6709;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;&#x4E3A;&#x4E86;&#x4FDD;&#x6301;&#x5185;&#x5B58;&#x7684;&#x4F7F;&#x7528;&#x5728;&#x4E00;&#x4E2A;&#x5408;&#x7406;&#x7684;&#x6C34;&#x5E73;&#xFF0C;<code>StatusManager</code> &#x7684;&#x9ED8;&#x8BA4;&#x5B9E;&#x73B0;&#x5305;&#x542B;&#x4E24;&#x4E2A;&#x90E8;&#x5206;&#xFF1A;&#x5934;&#x90E8;&#x4E0E;&#x5C3E;&#x90E8;&#x3002;&#x5934;&#x90E8;&#x5B58;&#x50A8;&#x7B2C;&#x4E00;&#x4E2A; <em>H</em> &#x72B6;&#x6001;&#x7684;&#x6D88;&#x606F;&#xFF0C;&#x5C3E;&#x90E8;&#x5B58;&#x50A8;&#x6700;&#x540E;&#x4E00;&#x4E2A; <em>T</em> &#x72B6;&#x6001;&#x7684;&#x6D88;&#x606F;&#x3002;&#x76EE;&#x524D; <em>H=T=150</em>&#xFF0C;&#x8FD9;&#x4E2A;&#x503C;&#x5728;&#x4EE5;&#x540E;&#x53EF;&#x80FD;&#x4F1A;&#x6539;&#x53D8;&#x3002;</p>
<p>logback-classic &#x5305;&#x542B;&#x4E00;&#x4E2A;&#x540D;&#x53EB; ViewStatusMessagesServlet &#x7684; servlet&#x3002;&#x8FD9;&#x4E2A; servlet &#x6253;&#x5370;&#x5F53;&#x524D; LoggerContext &#x7684; StatusManager &#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x901A;&#x8FC7; html &#x8FDB;&#x884C;&#x8F93;&#x51FA;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<p><img src="images/statusMessages.png" alt="statusMessages"></p>
<p>&#x5728; <em>WEB-INF/web.xml</em> &#x4E2D;&#x6DFB;&#x52A0;&#x5982;&#x4E0B;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">servlet</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>ViewStatusMessages<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-class</span>&gt;</span>ch.qos.logback.classic.ViewStatusMessagesServlet<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-class</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">servlet</span>&gt;</span>

<span class="hljs-tag">&lt;<span class="hljs-name">servlet-mapping</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">servlet-name</span>&gt;</span>ViewStatusMessages<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-name</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">url-pattern</span>&gt;</span>/lbClassicStatus<span class="hljs-tag">&lt;/<span class="hljs-name">url-pattern</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">servlet-mapping</span>&gt;</span>
</code></pre>
<p>&#x7136;&#x540E;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>http://host/yourWebapp/lbClassicStatus</code> &#x8FDB;&#x884C;&#x8BBF;&#x95EE;&#x3002;</p>
<h3 id="&#x76D1;&#x542C;&#x72B6;&#x6001;&#x4FE1;&#x606F;">&#x76D1;&#x542C;&#x72B6;&#x6001;&#x4FE1;&#x606F;</h3>
<p>&#x901A;&#x8FC7;&#x7ED9; <code>StatusManager</code> &#x9644;&#x52A0;&#x4E00;&#x4E2A; <code>StatusListener</code>&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x8FDB;&#x884C;&#x83B7;&#x53D6;&#x3002;&#x7279;&#x522B;&#x662F;&#x5728;&#x914D;&#x7F6E;&#x597D; logback &#x4E4B;&#x540E;&#x3002;&#x6CE8;&#x518C;&#x4E00;&#x4E2A;&#x72B6;&#x6001;&#x76D1;&#x542C;&#x5668;&#x53EF;&#x4EE5;&#x5F88;&#x65B9;&#x4FBF;&#x7684;&#x76D1;&#x542C; logback &#x7684;&#x5185;&#x90E8;&#x72B6;&#x6001;&#xFF0C;&#x5E76;&#x4E14;&#x4E0D;&#x9700;&#x8981;&#x4EBA;&#x5DE5;&#x7684;&#x5E72;&#x9884;&#x3002;</p>
<p> <code>StatusListener</code> &#x6709;&#x4E00;&#x4E2A;&#x540D;&#x4E3A; <code>OnConsoleStatusListener</code> &#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x51FA;&#x6765;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-keyword">public</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AddStatusListenerApp</span> </span>{

    <span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">main</span><span class="hljs-params">(String[] args)</span> </span>{

        LoggerContext lc = (LoggerContext)LoggerFactory.getILoggerFactory();
        StatusManager statusManager = lc.getStatusManager();
        OnConsoleStatusListener onConsoleStatusListener = <span class="hljs-keyword">new</span> OnConsoleStatusListener();
        statusManager.add(onConsoleStatusListener);

        Logger logger = LoggerFactory.getLogger(<span class="hljs-string">&quot;myApp&quot;</span>);
        logger.info(<span class="hljs-string">&quot;Entering application&quot;</span>);

        Foo foo = <span class="hljs-keyword">new</span> Foo();
        foo.doIt();
        logger.info(<span class="hljs-string">&quot;Exiting application&quot;</span>);

        StatusPrinter.print(statusManager);
    }
}
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x6CE8;&#x518C;&#x7684;&#x72B6;&#x6001;&#x76D1;&#x542C;&#x5668;&#x53EA;&#x4F1A;&#x83B7;&#x53D6;&#x6CE8;&#x518C;&#x4E4B;&#x540E;&#x4EA7;&#x751F;&#x7684;&#x72B6;&#x6001;&#x6D88;&#x606F;&#xFF0C;&#x800C;&#x4E0D;&#x4F1A;&#x83B7;&#x53D6;&#x6CE8;&#x518C;&#x4E4B;&#x524D;&#x4EA7;&#x751F;&#x7684;&#x6D88;&#x606F;&#x3002;&#x6240;&#x4EE5;&#x5EFA;&#x8BAE;&#x5728;&#x6700;&#x5F00;&#x59CB;&#x7684;&#x65F6;&#x5019;&#x76F4;&#x63A5;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#x3002;</p>
</blockquote>
<p>&#x53EF;&#x4EE5;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x914D;&#x7F6E;&#x591A;&#x4E2A;&#x72B6;&#x6001;&#x76D1;&#x542C;&#x5668;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">statusListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.status.OnConsoleStatusListener&quot;</span> /&gt;</span>  

  ... the rest of the configuration file  
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;-logbackstatuslistenerclass">&#x7CFB;&#x7EDF;&#x5C5E;&#x6027; &quot;logback.statusListenerClass&quot;</h3>
<p>&#x901A;&#x8FC7;&#x8BBE;&#x7F6E; java &#x7684;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#x6765;&#x914D;&#x7F6E;&#x72B6;&#x6001;&#x76D1;&#x542C;&#x5668;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-bash">java -Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener
</code></pre>
<p>logback &#x5B50;&#x7EA7;&#x5B9E;&#x73B0;&#x4E86;&#x51E0;&#x4E2A;&#x76D1;&#x542C;&#x5668;&#x3002;<a href="https://logback.qos.ch/xref/ch/qos/logback/core/status/OnConsoleStatusListener.html" target="_blank">OnConsoleStatusListener</a> &#x7528;&#x4E8E;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x72B6;&#x6001;&#x6D88;&#x606F;&#x3002;<a href="https://logback.qos.ch/xref/ch/qos/logback/core/status/OnErrorConsoleStatusListener.html" target="_blank">OnErrorConsoleStatusListener</a> &#x7528;&#x4E8E;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x663E;&#x793A;&#x9519;&#x8BEF;&#x7684;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;<a href="https://logback.qos.ch/xref/ch/qos/logback/core/status/NopStatusListener.html" target="_blank">NopStatusListener</a> &#x4F1A;&#x4E22;&#x5F03;&#x6389;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5728;&#x914D;&#x7F6E;&#x671F;&#x95F4;&#xFF0C;&#x4EFB;&#x4F55;&#x7684;&#x72B6;&#x6001;&#x76D1;&#x542C;&#x5668;&#x88AB;&#x6CE8;&#x518C;&#xFF0C;&#x6216;&#x8005;&#x901A;&#x8FC7; java &#x7CFB;&#x7EDF;&#x53D8;&#x91CF;&#x6307;&#x5B9A; <code>logback.statusListenerClass</code> &#x7684;&#x503C;&#xFF0C;<a href="#&#x5728;&#x8B66;&#x544A;&#x6216;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x81EA;&#x52A8;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;">&#x5728;&#x8B66;&#x544A;&#x6216;&#x9519;&#x8BEF;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x81EA;&#x52A8;&#x6253;&#x5370;&#x72B6;&#x6001;&#x4FE1;&#x606F;</a> &#x5C06;&#x4F1A;&#x88AB;&#x7981;&#x7528;&#x3002;</p>
</blockquote>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8BBE;&#x7F6E; java &#x7CFB;&#x7EDF;&#x53D8;&#x91CF; <code>logback.statusListenerClass</code> &#x7684;&#x503C;&#x6765;&#x7981;&#x7528;&#x4E00;&#x5207;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x7684;&#x6253;&#x5370;&#x3002;</p>
<pre><code class="lang-bash">java -Dlogback.statusListenerClass=ch.qos.logback.core.status.NopStatusListener
</code></pre>
<h2 id="&#x505C;&#x6B62;-logback-classic">&#x505C;&#x6B62; logback-classic</h2>
<p>&#x4E3A;&#x4E86;&#x91CA;&#x653E; logback-classic &#x6240;&#x4F7F;&#x7528;&#x7684;&#x8D44;&#x6E90;&#xFF0C;&#x505C;&#x6B62;&#x4F7F;&#x7528; logger context &#x662F;&#x4E00;&#x4E2A;&#x597D;&#x6CE8;&#x610F;&#x3002;&#x505C;&#x6B62; context &#x5C06;&#x4F1A;&#x5173;&#x95ED;&#x6240;&#x6709;&#x5728; logger &#x4E0A;&#x5B9A;&#x4E49;&#x7684; appender&#xFF0C;&#x5E76;&#x4E14;&#x6709;&#x5E8F;&#x7684;&#x505C;&#x6B62;&#x6B63;&#x5728;&#x6D3B;&#x52A8;&#x7684;&#x7EBF;&#x7A0B;&#x3002;</p>
<pre><code class="lang-java"><span class="hljs-keyword">import</span> org.sflf4j.LoggerFactory;
<span class="hljs-keyword">import</span> ch.qos.logback.classic.LoggerContext;
...

LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.stop();
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x5728; web &#x5E94;&#x7528;&#x4E2D;&#xFF0C;&#x901A;&#x8FC7;&#x8C03;&#x7528; <code>ServletContextListener</code> &#x7684; <a href="http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html#contextDestroyed(javax.servlet.ServletContextEvent" target="_blank">contextDestroyed</a>) &#x65B9;&#x6CD5;&#x6765;&#x505C;&#x6B62; logback-classic &#x5E76;&#x91CA;&#x653E;&#x8D44;&#x6E90;&#x3002;1.1.10 &#x7248;&#x672C;&#x540E;&#xFF0C;<code>ServletContextListener</code> &#x4F1A;&#x88AB;&#x81EA;&#x52A8;&#x52A0;&#x8F7D;&#x3002;</p>
<h4 id="&#x901A;&#x8FC7;-shutddown-hook-&#x505C;&#x6B62;-logback-classic">&#x901A;&#x8FC7; shutddown hook &#x505C;&#x6B62; logback-classic</h4>
<blockquote>
<p>&#x4E2A;&#x4EBA;&#x89C9;&#x5F97; hook &#x53EF;&#x4EE5;&#x7406;&#x89E3;&#x4E3A;&#x94A9;&#x5B50;&#x6216;&#x8005;&#x5F00;&#x5173;&#xFF0C;&#x4F46;&#x662F;&#x8FD8;&#x662F;&#x89C9;&#x5F97;&#x7167;&#x5199;&#x4F1A;&#x66F4;&#x597D;&#x7406;&#x89E3;&#x4E00;&#x70B9;&#x3002;</p>
</blockquote>
<p>&#x6307;&#x5B9A;&#x4E00;&#x4E2A; JVM shutdown hook &#x53EF;&#x4EE5;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x7684;&#x5173;&#x95ED; logback &#x5E76;&#x91CA;&#x653E;&#x8D44;&#x6E90;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x5982;&#x679C;&#x7F3A;&#x5931; class &#x5C5E;&#x6027;&#xFF0C;&#x5219;&#x4F1A;&#x9ED8;&#x8BA4;&#x52A0;&#x8F7D; ch.qos.logback.core.hook.DefaultShutdownHook --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">shutdownHook</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <em>class</em> &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x4E00;&#x4E2A; shutdown hook &#x7684;&#x540D;&#x5B57;&#x3002;</p>
</blockquote>
<p>&#x9ED8;&#x8BA4;&#x7684; shutdown hook &#x4E3A; <a href="https://logback.qos.ch/apidocs/ch/qos/logback/core/hook/DefaultShutdownHook.html" target="_blank">DefaultShutdownHook</a>&#xFF0C;&#x5728;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684;&#x65F6;&#x95F4;&#x540E;&#xFF08;&#x9ED8;&#x8BA4;&#x662F; 0&#xFF09;&#x4F1A;&#x505C;&#x6389; context&#x3002;&#x4F46;&#x662F;&#x5141;&#x8BB8; context &#x5728; 30s &#x5185;&#x5B8C;&#x6210;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x7684;&#x6253;&#x5305;&#x3002;&#x5728;&#x72EC;&#x7ACB;&#x7684; java &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E2D;&#xFF0C;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x6DFB;&#x52A0; <code>&lt;shutdownHook/&gt;</code> &#x53EF;&#x4EE5;&#x786E;&#x4FDD;&#x4EFB;&#x4F55;&#x65E5;&#x5FD7;&#x6253;&#x5305;&#x4EFB;&#x52A1;&#x5B8C;&#x6210;&#x4E4B;&#x540E;&#xFF0C;JVM &#x624D;&#x4F1A;&#x9000;&#x51FA;&#x3002;&#x5728; web &#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x4E2D;&#xFF0C;<a href="https://logback.qos.ch/manual/configuration.html#webShutdownHook" target="_blank">webShutdownHook</a> &#x4F1A;&#x81EA;&#x52A8;&#x5B89;&#x88C5;&#xFF0C;<code>&lt;shutdownHook/&gt;</code> &#x5C06;&#x4F1A;&#x53D8;&#x7684;&#x591A;&#x4F59;&#x4E14;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x3002;</p>
<h4 id="&#x5728;-web-&#x5E94;&#x7528;&#x4E2D;&#x4F7F;&#x7528;-webshutdownhook-&#x505C;&#x6B62;-logback-classic">&#x5728; web &#x5E94;&#x7528;&#x4E2D;&#x4F7F;&#x7528; WebShutdownHook &#x505C;&#x6B62; logback-classic</h4>
<p><code>SINCE 1.1.10</code> logback-classic &#x4F1A;&#x81EA;&#x52A8;&#x8981;&#x6C42; web &#x670D;&#x52A1;&#x5B89;&#x88C5; <a href="https://logback.qos.ch/apidocs/ch/qos/logback/classic/servlet/LogbackServletContainerInitializer.html" target="_blank">LogbackServletContainerInitializer</a>&#xFF08;&#x5B9E;&#x73B0;&#x4E86; <code>ServletContainerInitializer</code> &#x63A5;&#x53E3;&#xFF0C;&#x5728; servlet-api 3.x &#x6216;&#x4EE5;&#x540E;&#x7684;&#x7248;&#x672C;&#x624D;&#x6709;&#x6548;&#xFF09;&#x3002;&#x8FD9;&#x4E2A;&#x521D;&#x59CB;&#x5316;&#x7A0B;&#x5E8F;&#x5C06;&#x4F1A;&#x4F9D;&#x6B21;&#x5B9E;&#x4F8B;&#x5316; <a href="https://logback.qos.ch/apidocs/ch/qos/logback/classic/servlet/LogbackServletContextListener.html" target="_blank">LogbackServletContextListener</a> &#x7684;&#x5B9E;&#x4F8B;&#x3002;&#x5728; web &#x5E94;&#x7528;&#x505C;&#x6B62;&#x6216;&#x8005;&#x91CD;&#x8F7D;&#x7684;&#x65F6;&#x5019;&#x4F1A;&#x505C;&#x6389;&#x5F53;&#x524D; logback-classic &#x7684; context&#x3002;</p>
<blockquote>
<p>&#x6211;&#x8868;&#x793A;&#x4E0D;&#x662F;&#x5F88;&#x61C2;&#x8FD9;&#x79CD;&#x505A;&#x6CD5;&#x6709;&#x4F55;&#x610F;&#x4E49;&#xFF0C;&#x96BE;&#x9053;&#x5E94;&#x7528;&#x90FD;&#x505C;&#x6B62;&#x4E86;&#xFF0C;context &#x8FD8;&#x4F1A;&#x5728;&#x8FD0;&#x884C;&#xFF1F;&#x8FD9;&#x5C31;&#x662F;&#x4F5C;&#x8005;&#x8BF4;&#x7684;&#x975E;&#x5E38;&#x591A;&#x4F59;&#x8DDF;&#x6CA1;&#x6709;&#x5FC5;&#x8981;&#x5417;&#xFF1F;</p>
</blockquote>
<p>&#x53EF;&#x4EE5;&#x5728; web.xml &#x4E2D;&#x7981;&#x6B62; <code>LogbackServletContextListener</code> &#x7684;&#x5B9E;&#x4F8B;&#x5316;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">web-app</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">context-param</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">param-name</span>&gt;</span>logbackDisableServletContainerInitializer<span class="hljs-tag">&lt;/<span class="hljs-name">param-name</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">param-value</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">param-value</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">context-param</span>&gt;</span>
    ...
<span class="hljs-tag">&lt;/<span class="hljs-name">web-app</span>&gt;</span>
</code></pre>
<p><code>logbackDisableServletContainerInitializer</code> &#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; java &#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#x6216;&#x8005;&#x7CFB;&#x7EDF;&#x7684;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x6765;&#x8BBE;&#x7F6E;&#x3002;&#x4F18;&#x5148;&#x7EA7;&#x4E3A;&#xFF1A;web &#x5E94;&#x7528; &gt; java &#x7CFB;&#x7EDF;&#x5C5E;&#x6027; &gt; &#x7CFB;&#x7EDF;&#x73AF;&#x5883;&#x53D8;&#x91CF;</p>
<h2 id="&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x8BED;&#x6CD5;">&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x8BED;&#x6CD5;</h2>
<p>logback &#x5141;&#x8BB8;&#x4F60;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x65E5;&#x5FD7;&#x7684;&#x884C;&#x4E3A;&#x800C;&#x4E0D;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x7F16;&#x8BD1;&#x4EE3;&#x7801;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8F7B;&#x6613;&#x7684;&#x7981;&#x7528;&#x8C03;&#x5E94;&#x7528;&#x4E2D;&#x67D0;&#x4E9B;&#x90E8;&#x5206;&#x7684;&#x65E5;&#x5FD7;&#xFF0C;&#x6216;&#x8005;&#x5C06;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x5230;&#x4EFB;&#x4F55;&#x5730;&#x65B9;&#x3002;</p>
<p>logback &#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x975E;&#x5E38;&#x7684;&#x7075;&#x6D3B;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x6307;&#x5B9A; DTD &#x6216;&#x8005; xml &#x6587;&#x4EF6;&#x9700;&#x8981;&#x7684;&#x8BED;&#x6CD5;&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x6700;&#x57FA;&#x672C;&#x7684;&#x7ED3;&#x6784;&#x4E3A; <code>&lt;configuration&gt;</code> &#x5143;&#x7D20;&#xFF0C;&#x5305;&#x542B; 0 &#x6216;&#x591A;&#x4E2A; <code>&lt;appender&gt;</code> &#x5143;&#x7D20;&#xFF0C;&#x5176;&#x540E;&#x8DDF; 0 &#x6216;&#x591A;&#x4E2A; <code>&lt;logger&gt;</code> &#x5143;&#x7D20;&#xFF0C;&#x5176;&#x540E;&#x518D;&#x8DDF;&#x6700;&#x591A;&#x53EA;&#x80FD;&#x5B58;&#x5728;&#x4E00;&#x4E2A;&#x7684; <code>&lt;root&gt;</code> &#x5143;&#x7D20;&#x3002;&#x57FA;&#x672C;&#x7ED3;&#x6784;&#x56FE;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="images/basicSyntax.png" alt="basicSyntax"></p>
<h4 id="&#x6807;&#x7B7E;&#x540D;&#x5927;&#x5C0F;&#x5199;&#x654F;&#x611F;">&#x6807;&#x7B7E;&#x540D;&#x5927;&#x5C0F;&#x5199;&#x654F;&#x611F;</h4>
<p>&#x5728; logback &#x7248;&#x672C; 0.9.17 &#x4E4B;&#x540E;&#xFF0C;&#x663E;&#x793A;&#x89C4;&#x5B9A;&#x7684;&#x6807;&#x7B7E;&#x540D;&#x4E0D;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x3002;&#x4F8B;&#x5982;&#xFF1A;<code>&lt;logger&gt;</code>&#x3001;<code>&lt;Logger</code>&#x3001;<code>&lt;LOGGER&gt;</code> &#x8FD9;&#x4E9B;&#x90FD;&#x662F;&#x6709;&#x6548;&#x7684;&#x6807;&#x7B7E;&#x540D;&#x3002;xml &#x98CE;&#x683C;&#x7684;&#x89C4;&#x5219;&#x4ECD;&#x7136;&#x9002;&#x7528;&#x3002;&#x5982;&#x679C;&#x4F60;&#x6709;&#x4E00;&#x4E2A;&#x5F00;&#x59CB;&#x6807;&#x7B7E;&#x4E3A; &lt;xyz&gt;&#xFF0C;&#x90A3;&#x4E48;&#x5FC5;&#x987B;&#x8981;&#x6709;&#x4E00;&#x4E2A;&#x7ED3;&#x675F;&#x6807;&#x7B7E; &lt;/xyz&gt;&#x3002;&lt;/XyZ&gt; &#x5219;&#x662F;&#x9519;&#x8BEF;&#x7684;&#x3002;&#x6839;&#x636E;<a href="#&#x9ED8;&#x8BA4;&#x89C4;&#x5219;">&#x9ED8;&#x8BA4;&#x89C4;&#x5219;</a>&#xFF0C;&#x6807;&#x7B7E;&#x540D;&#x5B57;&#x662F;&#x5927;&#x5C0F;&#x5199;&#x654F;&#x611F;&#x7684;&#xFF0C;&#x9664;&#x4E86;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x6BCD;&#x3002;&#x6240;&#x4EE5;&#xFF0C;&lt;xyz&gt; &#x4E0E; &lt;Xyz&gt; &#x662F;&#x4E00;&#x6837;&#x7684;&#xFF0C;&#x4F46;&#x662F; &lt;xYz&gt; &#x662F;&#x9519;&#x8BEF;&#x7684;&#x3002;&#x9ED8;&#x8BA4;&#x89C4;&#x5219;&#x9075;&#x5FAA;&#x9A7C;&#x5CF0;&#x547D;&#x540D;&#x6CD5;&#x3002;&#x5F88;&#x96BE;&#x8BF4;&#x6E05;&#x695A;&#x4E00;&#x4E2A;&#x6807;&#x7B7E;&#x9075;&#x5FAA;&#x4EC0;&#x4E48;&#x89C4;&#x5219;&#xFF0C;&#x5982;&#x679C;&#x4F60;&#x4E0D;&#x77E5;&#x9053;&#x7ED9;&#x5B9A;&#x7684;&#x6807;&#x7B7E;&#x9075;&#x5FAA;&#x54EA;&#x79CD;&#x89C4;&#x5219;&#xFF0C;&#x90A3;&#x4E48;&#x4F7F;&#x7528;&#x9A7C;&#x5CF0;&#x547D;&#x540D;&#x6CD5;&#x603B;&#x662F;&#x6B63;&#x786E;&#x7684;&#x3002;</p>
<h4 id="&#x914D;&#x7F6E;-logger">&#x914D;&#x7F6E; logger</h4>
<p>&#x73B0;&#x5728;&#x4F60;&#x81F3;&#x5C11;&#x5E94;&#x8BE5;&#x5BF9;<a href="https://github.com/Volong/logback-chinese-manual/blob/0197a2d5a3820d9c1756c680c2e21e934904c6a6/02%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9A%E6%9E%B6%E6%9E%84.md#%E6%9C%89%E6%95%88%E7%AD%89%E7%BA%A7%E5%8F%88%E7%A7%B0%E4%B8%BA%E7%AD%89%E7%BA%A7%E7%BB%A7%E6%89%BF" target="_blank">&#x7B49;&#x7EA7;&#x7EE7;&#x627F;&#x89C4;&#x5219;</a>&#x4E0E;<a href="https://github.com/Volong/logback-chinese-manual/blob/0197a2d5a3820d9c1756c680c2e21e934904c6a6/02%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9A%E6%9E%B6%E6%9E%84.md#%E6%96%B9%E6%B3%95%E6%89%93%E5%8D%B0%E4%BB%A5%E5%8F%8A%E5%9F%BA%E6%9C%AC%E9%80%89%E6%8B%A9%E8%A7%84%E5%88%99" target="_blank">&#x57FA;&#x672C;&#x89C4;&#x5219;</a>&#x6709;&#x6240;&#x4E86;&#x89E3;.&#x3002;</p>
<p>&#x901A;&#x8FC7; <code>&lt;logger&gt;</code> &#x6807;&#x7B7E;&#x6765;&#x8FC7; logger &#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF0C;&#x4E00;&#x4E2A; <code>&lt;logger&gt;</code> &#x6807;&#x7B7E;&#x5FC5;&#x987B;&#x5305;&#x542B;&#x4E00;&#x4E2A; <em>name</em> &#x5C5E;&#x6027;&#xFF0C;&#x4E00;&#x4E2A;&#x53EF;&#x9009;&#x7684; <em>level</em> &#x5C5E;&#x6027;&#xFF0C;&#x4E00;&#x4E2A;&#x53EF;&#x9009; <em>additivity</em> &#x5C5E;&#x6027;&#x3002;<code>additivity</code> &#x7684;&#x503C;&#x4E3A; <em>true</em> &#x6216; <em>false</em>&#x3002;<code>level</code> &#x7684;&#x503C;&#x4E3A; TRACE&#xFF0C;DEBUG&#xFF0C;INFO&#xFF0C;WARN&#xFF0C;ERROR&#xFF0C;ALL&#xFF0C;OFF&#xFF0C;INHERITED&#xFF0C;NULL&#x3002;&#x5F53; <code>level</code> &#x7684;&#x503C;&#x4E3A; INHERITED &#x6216; NULL &#x65F6;&#xFF0C;&#x5C06;&#x4F1A;&#x5F3A;&#x5236; logger &#x7EE7;&#x627F;&#x4E0A;&#x4E00;&#x5C42;&#x7684;&#x7EA7;&#x522B;&#x3002;</p>
<p><code>&lt;logger&gt;</code> &#x5143;&#x7D20;&#x81F3;&#x5C11;&#x5305;&#x542B; 0 &#x6216;&#x591A;&#x4E2A; <code>&lt;appender-ref&gt;</code> &#x5143;&#x7D20;&#x3002;&#x6BCF;&#x4E00;&#x4E2A; appender &#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x88AB;&#x6DFB;&#x52A0;&#x5230; logger &#x4E0A;&#x3002;&#x4E0E; log4j &#x4E0D;&#x540C;&#x7684;&#x662F;&#xFF0C;logbakc-classic &#x4E0D;&#x4F1A;&#x5173;&#x95ED;&#x6216;&#x79FB;&#x9664;&#x4EFB;&#x4F55;&#x4E4B;&#x524D;&#x5728; logger &#x4E0A;&#x5B9A;&#x4E49;&#x597D;&#x7684;&#x7684; appender&#x3002;</p>
<h4 id="&#x914D;&#x7F6E;-root-logger">&#x914D;&#x7F6E; root logger</h4>
<p>root logger &#x901A;&#x8FC7; <code>&lt;root&gt;</code> &#x5143;&#x7D20;&#x6765;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#x3002;&#x5B83;&#x53EA;&#x652F;&#x6301;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x2014;&#x2014;<code>level</code>&#x3002;&#x5B83;&#x4E0D;&#x5141;&#x8BB8;&#x8BBE;&#x7F6E;&#x5176;&#x5B83;&#x4EFB;&#x4F55;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x56E0;&#x4E3A; additivity &#x5E76;&#x4E0D;&#x9002;&#x7528; root logger&#x3002;&#x800C;&#x4E14;&#xFF0C;root logger &#x7684;&#x540D;&#x5B57;&#x5DF2;&#x7ECF;&#x88AB;&#x547D;&#x540D;&#x4E3A; &quot;ROOT&quot;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x4E5F;&#x4E0D;&#x652F;&#x6301; name &#x5C5E;&#x6027;&#x3002;level &#x5C5E;&#x6027;&#x7684;&#x503C;&#x53EF;&#x4EE5;&#x4E3A;&#xFF1A;TRACE&#x3001;DEBUG&#x3001;INFO&#x3001;WARN&#x3001;ERROR&#x3001;ALL&#x3001;OFF&#xFF0C;&#x4F46;&#x662F;&#x4E0D;&#x80FD;&#x8BBE;&#x7F6E;&#x4E3A; INHERITED  &#x6216; NULL&#x3002;</p>
<p>&#x8DDF; <code>&lt;logger</code> &#x5143;&#x7D20;&#x7C7B;&#x4F3C;&#xFF0C;<code>&lt;root&gt;</code> &#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x5305;&#x542B; 0 &#x6216;&#x591A;&#x4E2A; <code>&lt;appender-ref&gt;</code> &#x5143;&#x7D20;&#x3002;</p>
<h4 id="&#x4F8B;&#x5B50;">&#x4F8B;&#x5B50;</h4>
<p>&#x5982;&#x679C;&#x6211;&#x4EEC;&#x4E0D;&#x60F3;&#x770B;&#x5230;&#x5C5E;&#x4E8E; &quot;chapters.configuration&quot; &#x7EC4;&#x4EF6;&#x4E2D;&#x4EFB;&#x4F55;&#x7684; DEBUG &#x4FE1;&#x606F;&#x3002;</p>
<p><em>Example</em>&#xFF1A;sample2.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration&quot;</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;INFO&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD0;&#x884C; <em>MyApp3</em>&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5982;&#x4E0B;&#x7684;&#x8F93;&#x51FA;&#x4FE1;&#x606F;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">21</span>:<span class="hljs-number">52</span>:<span class="hljs-number">48.726</span> [main] INFO  chapters.configuration.MyApp3 - Entering application
<span class="hljs-number">21</span>:<span class="hljs-number">52</span>:<span class="hljs-number">48.728</span> [main] INFO  chapters.configuration.MyApp3 - Exiting application
</code></pre>
<p>&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;<a href="https://logback.qos.ch/xref/chapters/configuration/Foo.html" target="_blank">&quot;chapters.configuration.Foo&quot;</a> &#x7C7B;&#x4E2D;&#x7684; debug &#x4FE1;&#x606F;&#x6CA1;&#x6709;&#x88AB;&#x8F93;&#x51FA;&#x3002;</p>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x914D;&#x7F6E;&#x4EFB;&#x4F55; logger &#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x3002;&#x5728;&#x4E0B;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x6211;&#x4EEC;&#x8BBE;&#x7F6E; <em>chapters.configurations</em> &#x7684; logger &#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x4E3A; INFO&#xFF0C;&#x540C;&#x65F6;&#x8BBE;&#x7F6E; <em>chapters.configuration.Foo</em> &#x7684; logger &#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x4E3A; DEBUG&#x3002;</p>
<p><em>Example</em>&#xFF1A;sample3.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration&quot;</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;INFO&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration.Foo&quot;</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD0;&#x884C; <em>MyApp3</em> &#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5982;&#x4E0B;&#x7684;&#x8F93;&#x51FA;&#x4FE1;&#x606F;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">22</span>:<span class="hljs-number">06</span>:<span class="hljs-number">43.500</span> [main] INFO  chapters.configuration.MyApp3 - Entering application
<span class="hljs-number">22</span>:<span class="hljs-number">06</span>:<span class="hljs-number">43.502</span> [main] DEBUG chapters.configuration.Foo - Did it again!
<span class="hljs-number">22</span>:<span class="hljs-number">06</span>:<span class="hljs-number">43.502</span> [main] INFO  chapters.configuration.MyApp3 - Exiting application
</code></pre>
<p>&#x4E0B;&#x9762;&#x7684;&#x8868;&#x683C;&#x5217;&#x51FA;&#x4E86; <code>JoranConfigurator</code> &#x901A;&#x8FC7; <em>sample3.xml</em> &#x914D;&#x7F6E; logback &#x540E;&#xFF0C;logger &#x4EE5;&#x53CA;&#x5176;&#x5BF9;&#x5E94;&#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">Logger name</th>
<th style="text-align:center">&#x6307;&#x5B9A;&#x7EA7;&#x522B;</th>
<th style="text-align:center">&#x6709;&#x6548;&#x7EA7;&#x522B;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">root</td>
<td style="text-align:center">DEBUG</td>
<td style="text-align:center">DEBUG</td>
</tr>
<tr>
<td style="text-align:left">chapters.configuration</td>
<td style="text-align:center">INFO</td>
<td style="text-align:center">INFO</td>
</tr>
<tr>
<td style="text-align:left">chapters.configuration.MyApp3</td>
<td style="text-align:center">null</td>
<td style="text-align:center">INFO</td>
</tr>
<tr>
<td style="text-align:left">chapters.configuration.Foo</td>
<td style="text-align:center">DEBUG</td>
<td style="text-align:center">DEBUG</td>
</tr>
</tbody>
</table>
<p><code>MyApp3</code> &#x7C7B;&#x4E2D;&#x7684;&#x4E24;&#x6761;&#x65E5;&#x5FD7;&#x6D88;&#x606F;&#x7684;&#x7EA7;&#x522B;&#x90FD;&#x4E3A; INFO&#xFF0C;Foo.doIt() &#x4E2D;&#x7684; DEBUG &#x4FE1;&#x606F;&#x4E5F;&#x80FD;&#x591F;&#x8FDB;&#x884C;&#x8F93;&#x51FA;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;root logger &#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x6C38;&#x8FDC;&#x4E0D;&#x4F1A;&#x8BBE;&#x7F6E;&#x6210;&#x4E00;&#x4E2A;&#x975E;&#x7A7A;&#x7684;&#x503C;&#xFF0C;&#x9ED8;&#x8BA4;&#x662F; DEBUG&#x3002;</p>
</blockquote>
<p><a href="https://github.com/Volong/logback-chinese-manual/blob/0197a2d5a3820d9c1756c680c2e21e934904c6a6/02%E7%AC%AC%E4%BA%8C%E7%AB%A0%EF%BC%9A%E6%9E%B6%E6%9E%84.md#%E6%96%B9%E6%B3%95%E6%89%93%E5%8D%B0%E4%BB%A5%E5%8F%8A%E5%9F%BA%E6%9C%AC%E9%80%89%E6%8B%A9%E8%A7%84%E5%88%99" target="_blank">&#x57FA;&#x672C;&#x9009;&#x62E9;&#x6CD5;</a> &#x4F9D;&#x8D56;&#x88AB;&#x8C03;&#x7528; logger &#x7684;&#x6709;&#x6548;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#xFF0C;&#x800C;&#x5E76;&#x4E0D;&#x662F; appender &#x6240;&#x4F9D;&#x9644;&#x7684; logger &#x7684;&#x7EA7;&#x522B;&#x3002;logback &#x4F1A;&#x9996;&#x5148;&#x5224;&#x65AD;&#x65E5;&#x5FD7;&#x8BED;&#x53E5;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x88AB;&#x6253;&#x5370;&#xFF0C;&#x5982;&#x679C;&#x53EF;&#x4EE5;&#xFF0C;&#x5219;&#x4F1A;&#x5728; logger &#x7684;&#x5C42;&#x7EA7;&#x7ED3;&#x6784;&#x4E2D;&#x67E5;&#x627E; appender&#xFF0C;&#x800C;&#x4E0D;&#x7BA1;&#x5B83;&#x4EEC;&#x7684;&#x7EA7;&#x522B;&#x5982;&#x4F55;&#xFF08;&#x8868;&#x793A;&#x5F88;&#x8D39;&#x89E3;&#xFF0C;appender &#x672C;&#x6765;&#x5C31;&#x6CA1;&#x6709;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#xFF0C;&#x4E3A;&#x4EC0;&#x4E48;&#x4F1A;&#x5173; appender &#x7684;&#x4E8B;&#xFF1F;&#xFF09;&#x3002;&#x4E0B;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x8BF4;&#x660E;&#x4E86;&#x8FD9;&#x4E00;&#x70B9;&#x3002;</p>
<p><em>Example</em>&#xFF1A;sample4.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration&quot;</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;INFO&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;OFF&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x5982;&#x4E0B;&#x8868;&#x683C;&#x5C55;&#x793A;&#x4E86;&#x5E94;&#x7528; sample4.xml &#x4E4B;&#x540E;&#x7684;&#x5404; logger &#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x3002;</p>
<table>
<thead>
<tr>
<th>logger name</th>
<th>&#x5206;&#x914D;&#x7EA7;&#x522B;</th>
<th>&#x6709;&#x6548;&#x7EA7;&#x522B;</th>
</tr>
</thead>
<tbody>
<tr>
<td>root</td>
<td>OFF</td>
<td>OFF</td>
</tr>
<tr>
<td>chapters.configuration</td>
<td>INFO</td>
<td>INFO</td>
</tr>
<tr>
<td>chapters.configuration.MyApp3</td>
<td>null</td>
<td>INFO</td>
</tr>
<tr>
<td>chapters.configuration.Foo</td>
<td>null</td>
<td>INFO</td>
</tr>
</tbody>
</table>
<p>ConsoleAppender &#x7684;&#x540D;&#x5B57;&#x4E3A; <em>STDOUT</em>&#xFF0C; <em>sample4.xml</em> &#x4E2D;&#x552F;&#x4E00;&#x7684; appender&#xFF0C;&#x5B83;&#x6240;&#x4F9D;&#x9644;&#x7684; root logger &#x7684; level = OFF&#x3002;&#x4F46;&#x662F;&#xFF0C;&#x8FD0;&#x884C; <em>MyApp3</em> &#x8FD8;&#x662F;&#x5F97;&#x5230;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">10</span>:<span class="hljs-number">47</span>:<span class="hljs-number">34.310</span> [main] INFO  chapters.configuration.MyApp3 - Entering application
<span class="hljs-number">10</span>:<span class="hljs-number">47</span>:<span class="hljs-number">34.313</span> [main] INFO  chapters.configuration.MyApp3 - Exiting application
</code></pre>
<p>&#x5F88;&#x660E;&#x663E;&#xFF0C;root logger &#x6CA1;&#x6709;&#x5F71;&#x54CD;&#x5230;&#x5176;&#x4ED6;&#x7684; logger&#xFF0C;&#x56E0;&#x4E3A; <code>chapters.configuration.MyApp3</code> &#x4E0E; <code>chapters.configuration.Foo</code> &#x7C7B;&#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x4E3A; INFO&#x3002;&#x5373;&#x4F7F;&#x5728; java &#x4EE3;&#x7801;&#x4E2D;&#x6CA1;&#x6709;&#x76F4;&#x63A5;&#x5F15;&#x7528; <em>chapters.configuration</em> &#x8FD9;&#x4E2A; logger&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x662F;&#x5B58;&#x5728;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x58F0;&#x660E;&#x4E86;&#x3002;</p>
<h4 id="&#x914D;&#x7F6E;-appender">&#x914D;&#x7F6E; appender</h4>
<p>appender &#x901A;&#x8FC7; <code>&lt;appender&gt;</code> &#x5143;&#x7D20;&#x8FDB;&#x884C;&#x914D;&#x7F6E;&#xFF0C;&#x9700;&#x8981;&#x4E24;&#x4E2A;&#x5F3A;&#x5236;&#x7684;&#x5C5E;&#x6027; <em>name</em> &#x4E0E; <em>class</em>&#x3002;<em>name</em> &#x5C5E;&#x6027;&#x7528;&#x6765;&#x6307;&#x5B9A; appender &#x7684;&#x540D;&#x5B57;&#xFF0C;<em>class</em> &#x5C5E;&#x6027;&#x9700;&#x8981;&#x6307;&#x5B9A;&#x7C7B;&#x7684;&#x5168;&#x9650;&#x5B9A;&#x540D;&#x7528;&#x4E8E;&#x5B9E;&#x4F8B;&#x5316;&#x3002;<code>&lt;appender&gt;</code> &#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x5305;&#x542B; 0 &#x6216;&#x4E00;&#x4E2A; <code>&lt;layout&gt;</code> &#x5143;&#x7D20;&#xFF0C;0 &#x6216;&#x591A;&#x4E2A; <code>&lt;encoder&gt;</code> &#x5143;&#x7D20;&#xFF0C;0 &#x6216;&#x591A;&#x4E2A; <code>&lt;filter&gt;</code> &#x5143;&#x7D20;&#x3002;&#x9664;&#x4E86;&#x8FD9;&#x4E9B;&#x516C;&#x5171;&#x7684;&#x5143;&#x7D20;&#x4E4B;&#x5916;&#xFF0C;<code>&lt;appender&gt;</code> &#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x4EFB;&#x610F;&#x4E0E; appender &#x7C7B;&#x7684; JavaBean &#x5C5E;&#x6027;&#x76F8;&#x4E00;&#x81F4;&#x7684;&#x5143;&#x7D20;&#x3002;</p>
<p>&#x4E0B;&#x56FE;&#x5C55;&#x793A;&#x4E86;&#x4E00;&#x4E9B;&#x5E38;&#x89C1;&#x7684;&#x7ED3;&#x6784;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5BF9;&#x5C5E;&#x6027;&#x7684;&#x652F;&#x6301;&#x4E0D;&#x53EF;&#x89C1;&#xFF08;&#x6CA1;&#x61C2;&#x8FD9;&#x53E5;&#x8BDD;&#x662F;&#x4EC0;&#x4E48;&#x610F;&#x601D;&#xFF09;&#x3002;</p>
</blockquote>
<p><img src="images/appenderSyntax.png" alt="appenderSyntax"></p>
<p><code>&lt;layout&gt;</code> &#x5143;&#x7D20;&#x5F3A;&#x5236;&#x4E00;&#x4E2A; class &#x5C5E;&#x6027;&#x53BB;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x7C7B;&#x7684;&#x5168;&#x9650;&#x5B9A;&#x540D;&#xFF0C;&#x7528;&#x4E8E;&#x5B9E;&#x4F8B;&#x5316;&#x3002;&#x4E0E; <code>&lt;appender&gt;</code> &#x5143;&#x7D20;&#x4E00;&#x6837;&#xFF0C;<code>&lt;layout&gt;</code> &#x5143;&#x7D20;&#x4E5F;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x4E0E; layout &#x5B9E;&#x4F8B;&#x76F8;&#x5173;&#x7684;&#x5C5E;&#x6027;&#x3002;&#x5982;&#x679C; layout &#x7684; class &#x662F; <code>PatternLayout</code>&#xFF0C;&#x90A3;&#x4E48; class &#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x88AB;&#x9690;&#x85CF;&#x6389;&#xFF08;&#x53C2;&#x8003;&#xFF1A;<a href="#&#x9ED8;&#x8BA4;&#x7C7B;&#x6620;&#x5C04;">&#x9ED8;&#x8BA4;&#x7C7B;&#x6620;&#x5C04;</a>&#xFF09;&#xFF0C;&#x56E0;&#x4E3A;&#x8FD9;&#x4E2A;&#x5F88;&#x5E38;&#x89C1;&#x3002;.</p>
<p><code>&lt;encoder</code> &#x5143;&#x7D20;&#x5F3A;&#x5236;&#x4E00;&#x4E2A; class &#x5C5E;&#x6027;&#x53BB;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x7C7B;&#x7684;&#x5168;&#x9650;&#x5B9A;&#x540D;&#xFF0C;&#x7528;&#x4E8E;&#x5B9E;&#x4F8B;&#x5316;&#x3002;&#x5982;&#x679C; encoder &#x7684; class &#x662F; <code>PatternLayoutEncoder</code>&#xFF0C;&#x90A3;&#x4E48;&#x57FA;&#x4E8E;<a href="#&#x9ED8;&#x8BA4;&#x7C7B;&#x6620;&#x5C04;">&#x9ED8;&#x8BA4;&#x7C7B;&#x6620;&#x5C04;</a>&#xFF0C;class &#x5C5E;&#x6027;&#x53EF;&#x4EE5;&#x88AB;&#x9690;&#x85CF;&#x3002; </p>
<p>&#x901A;&#x8FC7;&#x591A;&#x4E2A; appender &#x8F93;&#x51FA;&#x65E5;&#x5FD7;&#x5C31;&#x50CF;&#x5B9A;&#x4E49;&#x591A;&#x4E2A; appender &#x4EE5;&#x53CA;&#x5C06;&#x5B83;&#x4EEC;&#x5173;&#x8054;&#x5230; logger &#x4E0A;&#x4E00;&#x6837;&#x7B80;&#x5355;&#x3002;</p>
<p><em>Example</em>&#xFF1A;multiple.xml</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
                %date %level [%thread] %logger{10} [%file:%line] %msg%n
            <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>
                %msg%n
            <span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5B9A;&#x4E49;&#x4E86;&#x4E24;&#x4E2A; appender&#xFF1A;<em>FILE</em> &#x548C; <em>STDOUT</em>&#x3002;<em>FILE</em> appender &#x5C06;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x5230; <em>myApp.log</em> &#x6587;&#x4EF6;&#x3002;encoder &#x901A;&#x8FC7; <code>PatternLayoutEncoder</code> &#x8F93;&#x51FA;&#x65E5;&#x671F;&#x3001;&#x65E5;&#x5FD7;&#x7B49;&#x7EA7;&#x3001;&#x7EBF;&#x7A0B;&#x540D;&#x3001;logger &#x7684;&#x540D;&#x5B57;&#x3001;&#x53EF;&#x4EE5;&#x5B9A;&#x4F4D;&#x65E5;&#x5FD7;&#x6765;&#x6E90;&#x7684;&#x6587;&#x4EF6;&#x4EE5;&#x53CA;&#x6240;&#x5728;&#x884C;&#x3001;&#x5177;&#x4F53;&#x7684;&#x65E5;&#x5FD7;&#x4FE1;&#x606F;&#x4EE5;&#x53CA;&#x884C;&#x5206;&#x9694;&#x7B26;&#x3002;&#x7B2C;&#x4E8C;&#x4E2A; appender &#x662F; <code>STDOUT</code>&#xFF0C;&#x5C06;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x5230;&#x63A7;&#x5236;&#x53F0;&#x3002;&#x5B83;&#x7684; encoder &#x4EC5;&#x4EC5;&#x8F93;&#x51FA;&#x65E5;&#x5FD7;&#x4FE1;&#x606F;&#x4EE5;&#x53CA;&#x884C;&#x5206;&#x9694;&#x7B26;&#x3002;</p>
<p>appender &#x901A;&#x8FC7; <em>appender-ref</em> &#x5143;&#x7D20;&#x9644;&#x52A0;&#x5230; root logger &#x4E0A;&#x3002;&#x6BCF;&#x4E00;&#x4E2A; appender &#x90FD;&#x6709;&#x81EA;&#x5DF1; encoder&#x3002;encoder &#x901A;&#x5E38;&#x4E0D;&#x4F1A;&#x8BBE;&#x8BA1;&#x6210;&#x7ED9;&#x6240;&#x6709;&#x7684; appender &#x5171;&#x4EAB;&#x3002;&#x5BF9;&#x4E8E; layout &#x4E5F;&#x662F;&#x5982;&#x6B64;&#x3002;&#x56E0;&#x6B64;&#xFF0C;logback &#x4E0D;&#x4F1A;&#x63D0;&#x4F9B;&#x4EFB;&#x4F55;&#x5171;&#x4EAB; encoder &#x548C; layout &#x7684;&#x8BED;&#x6CD5;&#x3002;</p>
<h4 id="&#x91CD;&#x590D;&#x4F7F;&#x7528;-appender">&#x91CD;&#x590D;&#x4F7F;&#x7528; appender</h4>
<p>&#x5728;&#x9ED8;&#x8BA4;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;appender &#x662F;&#x53EF;&#x4EE5;&#x91CD;&#x590D;&#x4F7F;&#x7528;&#x7684;&#xFF1A;logger &#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x9644;&#x52A0;&#x5230;&#x672C;&#x8EAB;&#x7684; appender &#x8F93;&#x51FA;&#x65E5;&#x5FD7;&#xFF0C;&#x540C;&#x6837;&#x7684;&#x4E5F;&#x53EF;&#x4EE5;&#x9644;&#x52A0;&#x5230;&#x8D77;&#x7956;&#x5148;&#x7684;&#x8EAB;&#x4E0A;&#xFF0C;&#x5E76;&#x8F93;&#x51FA;&#x65E5;&#x5FD7;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x5982;&#x679C;&#x540C;&#x4E00;&#x4E2A; appender &#x9644;&#x52A0;&#x5230;&#x591A;&#x4E2A; logger &#x8EAB;&#x4E0A;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x5BFC;&#x81F4;&#x65E5;&#x5FD7;&#x91CD;&#x590D;&#x6253;&#x5370;&#x3002;</p>
<p><em>Example</em>&#xFF1A;duplicate.xml</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">logger</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD0;&#x884C; <em>MyApp3</em>&#xFF0C;&#x5C06;&#x4F1A;&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#x7ED3;&#x679C;&#xFF1A;</p>
<pre><code class="lang-java"><span class="hljs-number">22</span>:<span class="hljs-number">43</span>:<span class="hljs-number">35.469</span> [main] INFO  chapters.configuration.MyApp3 - Entering application
<span class="hljs-number">22</span>:<span class="hljs-number">43</span>:<span class="hljs-number">35.469</span> [main] INFO  chapters.configuration.MyApp3 - Entering application
<span class="hljs-number">22</span>:<span class="hljs-number">43</span>:<span class="hljs-number">35.471</span> [main] DEBUG chapters.configuration.Foo - Did it again!
<span class="hljs-number">22</span>:<span class="hljs-number">43</span>:<span class="hljs-number">35.471</span> [main] DEBUG chapters.configuration.Foo - Did it again!
<span class="hljs-number">22</span>:<span class="hljs-number">43</span>:<span class="hljs-number">35.472</span> [main] INFO  chapters.configuration.MyApp3 - Exiting application
<span class="hljs-number">22</span>:<span class="hljs-number">43</span>:<span class="hljs-number">35.472</span> [main] INFO  chapters.configuration.MyApp3 - Exiting application
</code></pre>
<p>&#x6CE8;&#x610F;&#x65E5;&#x5FD7;&#x91CD;&#x590D;&#x8F93;&#x51FA;&#x4E86;&#xFF0C;&#x56E0;&#x4E3A; appender <em>STDOUT</em> &#x9644;&#x52A0;&#x5230;&#x4E86;&#x4E24;&#x4E2A; logger &#x8EAB;&#x4E0A;&#xFF1A;root &#x4EE5;&#x53CA; <em>chapters.configuration</em>&#x3002;&#x56E0;&#x4E3A; root logger &#x662F;&#x6240;&#x6709; logger &#x7684;&#x7956;&#x5148;&#xFF0C;<em>chapters.configuration</em> &#x662F; <em>chapters.configuration.MyApp3</em> &#x4EE5;&#x53CA; <em>chapters.configuraion.Foo</em> &#x7684;&#x7236;&#x7EA7;&#x3002;&#x6BCF;&#x4E00;&#x6B21;&#x65E5;&#x5FD7;&#x8BF7;&#x6C42;&#x90FD;&#x4F1A;&#x88AB;&#x6253;&#x5370;&#x4E24;&#x6B21;&#xFF0C;&#x4E00;&#x6B21;&#x662F;&#x901A;&#x8FC7; <em>STDOUT</em>&#xFF0C;&#x4E00;&#x6B21;&#x662F;&#x901A;&#x8FC7; <em>root</em>&#x3002;</p>
<p>appender &#x7684;&#x53E0;&#x52A0;&#x6027;&#x5E76;&#x4E0D;&#x662F;&#x4E3A;&#x65B0;&#x7528;&#x6237;&#x8BBE;&#x7F6E;&#x7684;&#x9677;&#x9631;&#x3002;&#x5B83;&#x662F; logback &#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x7684;&#x4E00;&#x4E2A;&#x7279;&#x6027;&#x3002;&#x4F8B;&#x5982;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8BA9;&#x7CFB;&#x7EDF;&#x4E2D;&#x6240;&#x6709;&#x7684;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x5230;&#x63A7;&#x5236;&#x53F0;&#x4E0A;&#xFF0C;&#x800C;&#x5176;&#x5B83;&#x7279;&#x5B9A;&#x7684;&#x65E5;&#x5FD7;&#x8F93;&#x51FA;&#x5230;&#x7279;&#x5B9A;&#x7684; appender &#x4E2D;&#x3002;</p>
<p><em>Example</em>&#xFF1A; restricted.xml</p>
<pre><code class="lang-xml"><span class="php"><span class="hljs-meta">&lt;?</span>xml version=<span class="hljs-string">&quot;1.0&quot;</span> encoding=<span class="hljs-string">&quot;UTF-8&quot;</span><span class="hljs-meta">?&gt;</span></span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%date %level [%thread] %logger{10} [%file:%line] %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">logger</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x63A7;&#x5236;&#x53F0;&#x4F1A;&#x6253;&#x5370;&#x6240;&#x6709;&#x7684;&#x65E5;&#x5FD7;&#xFF0C;&#x800C;&#x53EA;&#x6709;&#x5C5E;&#x4E8E; <em>chapters.configuration</em> &#x7684; logger &#x4EE5;&#x53CA;&#x5B83;&#x7684;&#x5B50;&#x7EA7; logger &#x7684;&#x65E5;&#x5FD7;&#x624D;&#x4F1A;&#x8F93;&#x51FA;&#x5230; <em>myApp.log</em> &#x6587;&#x4EF6;&#x3002;</p>
<h4 id="&#x91CD;&#x5199;&#x9ED8;&#x8BA4;&#x7684;&#x7D2F;&#x52A0;&#x884C;&#x4E3A;">&#x91CD;&#x5199;&#x9ED8;&#x8BA4;&#x7684;&#x7D2F;&#x52A0;&#x884C;&#x4E3A;</h4>
<p>&#x5982;&#x679C;&#x9ED8;&#x8BA4;&#x7684;&#x7D2F;&#x79EF;&#x884C;&#x4E3A;&#x5BF9;&#x4F60;&#x6765;&#x8BF4;&#x4E0D;&#x9002;&#x5408;&#xFF0C;&#x4F60;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E; additivity = false&#x3002;</p>
<p><em>Example</em>&#xFF1A;additivityFlag.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>foo.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%date %level [%thread] %logger{10} [%file : %line] %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">logger</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;chapters.configuration.Foo&quot;</span> <span class="hljs-attr">additivity</span>=<span class="hljs-string">&quot;false&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">logger</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;<em>FILE</em> appender &#x9644;&#x52A0;&#x5230;&#x4E86;&#x540D;&#x4E3A; <em>chaoters.configuration.Foo</em> &#x7684; logger &#x4E0A;&#x3002;&#x800C;&#x4E14;&#xFF0C;<em>chapters.configuration.Foo</em> &#x8BBE;&#x7F6E;&#x4E86; additivity = false&#xFF0C;&#x90A3;&#x4E48;&#x8FD9;&#x4E2A; logger &#x7684;&#x65E5;&#x5FD7;&#x5C06;&#x4F1A;&#x901A;&#x8FC7; <em>FILE</em> &#x8FD9;&#x4E2A; appender &#x8F93;&#x51FA;&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x7684;&#x7236;&#x7EA7; logger &#x5C06;&#x4E0D;&#x4F1A;&#x8F93;&#x51FA;&#x5C5E;&#x4E8E;&#x8FD9;&#x4E2A; logger &#x7684;&#x65E5;&#x5FD7;&#x3002;&#x8FD0;&#x884C; <em>MyApp3</em>&#xFF0C;&#x5C5E;&#x4E8E; <em>chapters.configuration.MyApp3</em> &#x8FD9;&#x4E2A; logger &#x7684;&#x65E5;&#x5FD7;&#x5C06;&#x4F1A;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x8F93;&#x51FA;&#xFF0C;&#x4F46;&#x662F;&#x5C5E;&#x4E8E; <em>chapters.configuration.Foo</em> &#x8FD9;&#x4E2A; logger &#x7684;&#x65E5;&#x5FD7;&#x53EA;&#x4F1A;&#x5728; <em>foo.log</em> &#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#x770B;&#x5230;&#x3002;</p>
<h3 id="&#x8BBE;&#x7F6E;-context-&#x7684;&#x540D;&#x5B57;">&#x8BBE;&#x7F6E; context &#x7684;&#x540D;&#x5B57;</h3>
<p>&#x5728;&#x4E4B;&#x524D;&#x7684;<a href="#Logger%20&#x4E0A;&#x4E0B;&#x6587;">&#x7AE0;&#x8282;</a>&#x4E2D;&#x63D0;&#x5230;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A; logger &#x90FD;&#x4F1A;&#x9644;&#x52A0;&#x5230;&#x4E00;&#x4E2A; logger context &#x4E0A;&#x53BB;&#x3002;&#x9ED8;&#x8BA4;&#x8FD9;&#x4E2A; logger context &#x7684;&#x540D;&#x5B57;&#x4E3A; &quot;default&quot;&#x3002;&#x4F46;&#x662F;&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>&lt;contextName&gt;</code> &#x8BBE;&#x7F6E;&#x5176;&#x5B83;&#x7684;&#x540D;&#x5B57;&#x3002;&#x4F46;&#x662F;&#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x8FC7;&#x4E00;&#x6B21;&#x5C31;&#x4E0D;&#x80FD;<a href="#https://logback.qos.ch/apidocs/ch/qos/logback/core/ContextBase.html#setName(java.lang.String">&#x518D;&#x8BBE;&#x7F6E;</a>)&#x3002;&#x5F53;&#x591A;&#x4E2A;&#x5E94;&#x7528;&#x8F93;&#x51FA;&#x65E5;&#x5FD7;&#x5230;&#x540C;&#x4E00;&#x4E2A;&#x76EE;&#x7684;&#x5730;&#xFF0C;&#x8BBE;&#x7F6E; logger context &#x7684;&#x540D;&#x5B57;&#x53EF;&#x4EE5;&#x66F4;&#x597D;&#x7684;&#x533A;&#x5206;&#x3002;</p>
<p><em>Example</em>&#xFF1A;contextName.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">contextName</span>&gt;</span>myAppName<span class="hljs-tag">&lt;/<span class="hljs-name">contextName</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d %contextName [%t] %level %logger{36} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="&#x53D8;&#x91CF;&#x66FF;&#x6362;">&#x53D8;&#x91CF;&#x66FF;&#x6362;</h3>
<p><strong><code>&#x6CE8;&#x610F;</code></strong>&#xFF1A;&#x65E9;&#x671F;&#x7248;&#x672C;&#x4F7F;&#x7528;&#x7684;&#x662F;&#x5C5E;&#x6027;&#x66FF;&#x6362;&#x800C;&#x4E0D;&#x662F;&#x53D8;&#x91CF;&#x66FF;&#x6362;</p>
<h4 id="&#x53D8;&#x91CF;&#x7684;&#x5B9A;&#x4E49;">&#x53D8;&#x91CF;&#x7684;&#x5B9A;&#x4E49;</h4>
<p>logback &#x652F;&#x6301;&#x53D8;&#x91CF;&#x7684;&#x5B9A;&#x4E49;&#x4EE5;&#x53CA;&#x66FF;&#x6362;&#xFF0C;&#x53D8;&#x91CF;&#x6709;&#x5B83;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x3002;&#x800C;&#x4E14;&#xFF0C;&#x53D8;&#x91CF;&#x53EF;&#x4EE5;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x5916;&#x90E8;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x4E2D;&#xFF0C;&#x751A;&#x81F3;&#x52A8;&#x6001;&#x5B9A;&#x4E49;&#x3002;</p>
<p><em>Example</em>&#xFF1A;variableSubstitution1.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;USER_NAME&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;/data/logs&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>${USER_NAME}/myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>    
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x5F00;&#x59CB;&#x5B9A;&#x4E49;&#x4E86;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x4E4B;&#x540E;&#x901A;&#x8FC7;&#x5F15;&#x7528;&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x6307;&#x5B9A;&#x4E86;&#x65E5;&#x5FD7;&#x6587;&#x4EF6;&#x7684;&#x8DEF;&#x5F84;&#x3002;</p>
<p><em>Example</em>&#xFF1A;variableSubstitution2.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>${USER_HOME}/myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>    
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;&#x5728; java &#x7684;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;&#x4E2D;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x540C;&#x6837;&#x7684;&#x53D8;&#x91CF;&#x540D;&#xFF0C;&#x8FBE;&#x5230;&#x7684;&#x6548;&#x679C;&#x662F;&#x4E00;&#x6837;&#x7684;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5982;&#x4E0B;&#x7684;&#x65B9;&#x5F0F;&#x53BB;&#x8FD0;&#x884C;&#xFF1A;</p>
<pre><code>java -DUSER_HOME=&quot;/data/logs&quot; MyApp3
</code></pre><p>&#x5F53;&#x9700;&#x8981;&#x5B9A;&#x4E49;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x8FD9;&#x4E9B;&#x53D8;&#x91CF;&#x653E;&#x5230;&#x4E00;&#x4E2A;&#x5355;&#x72EC;&#x7684;&#x6587;&#x4EF6;&#x4E2D;&#x3002;</p>
<p><em>Example</em>&#xFF1A;variableSubstitution3.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">file</span>=<span class="hljs-string">&quot;F:\project\logback-examples\src\main\resources\variables1.properties&quot;</span>/&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>${USER_HOME}/myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x5305;&#x542B;&#x4E86;&#x4E00;&#x4E2A;&#x5BF9;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x7684;&#x5F15;&#x7528;&#xFF1A;<em>variables1.properties</em>&#x3002;&#x8FD9;&#x4E2A;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x5305;&#x542B;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#xFF1A;</p>
<p><em>Example</em>&#xFF1A;variables1.properties</p>
<pre><code class="lang-properties">USER_HOME=/data/logs
</code></pre>
<p>&#x4E5F;&#x53EF;&#x4EE5;&#x5F15;&#x7528; classpath &#x4E0B;&#x7684;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">resource</span>=<span class="hljs-string">&quot;resource1.properties&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>${USER_HOME}/myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h4 id="&#x4F5C;&#x7528;&#x57DF;">&#x4F5C;&#x7528;&#x57DF;</h4>
<p>&#x5C5E;&#x6027;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x5206;&#x522B;&#x4E3A;&#x672C;&#x5730;&#xFF08;local scope&#xFF09;&#x3001;&#x4E0A;&#x4E0B;&#x6587;&#xFF08;context scope&#xFF09;&#x3001;&#x7CFB;&#x7EDF;&#xFF08;system scope&#xFF09;&#x3002;&#x9ED8;&#x8BA4;&#x4E3A;&#x672C;&#x5730;&#x4F5C;&#x7528;&#x57DF;&#x3002;</p>
<p><code>&#x672C;&#x5730;&#xFF08;local scope&#xFF09;</code>&#xFF1A;&#x672C;&#x5730;&#x8303;&#x56F4;&#x5185;&#x7684;&#x5C5E;&#x6027;&#x5B58;&#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7684;&#x52A0;&#x8F7D;&#x8FC7;&#x7A0B;&#x4E2D;&#x3002;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6BCF;&#x52A0;&#x8F7D;&#x4E00;&#x6B21;&#xFF0C;&#x53D8;&#x91CF;&#x5C31;&#x4F1A;&#x88AB;&#x91CD;&#x65B0;&#x5B9A;&#x4E49;&#x4E00;&#x6B21;&#x3002;</p>
<p><code>&#x4E0A;&#x4E0B;&#x6587;&#xFF08;context scope&#xFF09;</code>&#xFF1A;&#x4E0A;&#x4E0B;&#x6587;&#x8303;&#x56F4;&#x5185;&#x7684;&#x5C5E;&#x6027;&#x4F1A;&#x4E00;&#x76F4;&#x5B58;&#x5728;&#x4E0A;&#x4E0B;&#x6587;&#x88AB;&#x6E05;&#x9664;&#x3002;</p>
<p><code>&#x7CFB;&#x7EDF;&#xFF08;system scope&#xFF09;</code>&#xFF1A;&#x7CFB;&#x7EDF;&#x8303;&#x56F4;&#x5185;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x4F1A;&#x63D2;&#x5165;&#x5230; JVM &#x7684;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#x4E2D;&#xFF0C;&#x8DDF;&#x968F; JVM &#x4E00;&#x540C;&#x6D88;&#x4EA1;&#x3002;</p>
<p>&#x5728;&#x8FDB;&#x884C;&#x53D8;&#x91CF;&#x66FF;&#x6362;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x5148;&#x4ECE;&#x672C;&#x5730;&#x8303;&#x56F4;&#x53BB;&#x627E;&#xFF0C;&#x518D;&#x4ECE;&#x4E0A;&#x4E0B;&#x6587;&#x53BB;&#x627E;&#xFF0C;&#x518D;&#x4ECE;&#x7CFB;&#x7EDF;&#x5C5E;&#x6027;&#x4E2D;&#x53BB;&#x627E;&#xFF0C;&#x6700;&#x540E;&#x4F1A;&#x53BB;&#x7CFB;&#x7EDF;&#x7684;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#x4E2D;&#x53BB;&#x627E;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>&lt;property&gt;</code>&#x3001;<code>&lt;define&gt;</code>&#x3001;<code>&lt;insertFromJNDI&gt;</code> &#x5143;&#x7D20;&#x7684; <em>scope</em> &#x5C5E;&#x6027;&#x6765;&#x8BBE;&#x7F6E;&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x8303;&#x56F4;&#x3002;<em>scope</em> &#x5C5E;&#x6027;&#x53EF;&#x80FD;&#x7684;&#x503C;&#x4E3A;&#xFF1A;local&#xFF0C;context&#xFF0C;system&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#xFF0C;&#x5219;&#x9ED8;&#x8BA4;&#x4E3A; local&#x3002;</p>
<p><em>Example</em>&#xFF1A;contextScopedVariable.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">scope</span>=<span class="hljs-string">&quot;context&quot;</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;nodeId&quot;</span> <span class="hljs-attr">value</span>=<span class="hljs-string">&quot;firstNode&quot;</span>/&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>/data/${nodeId}/myApp.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x5728;&#x8FD9;&#x4E2A;&#x4F8B;&#x5B50;&#x4E2D;&#xFF0C;<em>nodeId</em> &#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x88AB;&#x5B9A;&#x4E49;&#x5728;&#x4E0A;&#x4E0B;&#x6587;&#x8303;&#x56F4;&#xFF0C;&#x5B83;&#x5728;&#x6BCF;&#x4E2A;&#x65E5;&#x5FD7;&#x4E8B;&#x4EF6;&#xFF0C;&#x751A;&#x81F3;&#x901A;&#x8FC7;&#x5E8F;&#x5217;&#x5316;&#x53D1;&#x9001;&#x5230;&#x8FDC;&#x7A0B;&#x670D;&#x52A1;&#x5668;&#x4E0A;&#x90FD;&#x6709;&#x6548;&#x3002;</p>
<h3 id="&#x53D8;&#x91CF;&#x7684;&#x9ED8;&#x8BA4;&#x503C;">&#x53D8;&#x91CF;&#x7684;&#x9ED8;&#x8BA4;&#x503C;</h3>
<p>&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5982;&#x679C;&#x67D0;&#x4E2A;&#x53D8;&#x91CF;&#x6CA1;&#x6709;&#x88AB;&#x58F0;&#x660E;&#xFF0C;&#x6216;&#x8005;&#x4E3A;&#x7A7A;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x5219;&#x975E;&#x5E38;&#x6709;&#x7528;&#x3002;&#x5728; bash shell &#x4E2D;&#xFF0C;&#x9ED8;&#x8BA4;&#x503C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <strong>&quot;:-&quot;</strong> &#x6765;&#x6307;&#x5B9A;&#x3002;&#x4F8B;&#x5982;&#xFF1A;&#x5047;&#x8BBE;&#x53D8;&#x91CF; <em>aName</em> &#x6CA1;&#x6709;&#x88AB;&#x5B9A;&#x4E49;&#xFF0C;<em>&quot;${aNme:-golden}&quot;</em> &#x4F1A;&#x88AB;&#x89E3;&#x91CA;&#x6210; &quot;golden&quot; &#x3002;</p>
<h3 id="&#x53D8;&#x91CF;&#x7684;&#x5D4C;&#x5957;">&#x53D8;&#x91CF;&#x7684;&#x5D4C;&#x5957;</h3>
<p>&#x53D8;&#x91CF;&#x7684;&#x540D;&#x5B57;&#x3001;&#x9ED8;&#x8BA4;&#x503C;&#x3001;&#x4EE5;&#x53CA;&#x503C;&#x90FD;&#x53EF;&#x4EE5;&#x5F15;&#x7528;&#x5176;&#x5B83;&#x7684;&#x53D8;&#x91CF;&#x3002;</p>
<h4 id="&#x5D4C;&#x5957;&#x503C;">&#x5D4C;&#x5957;&#x503C;</h4>
<p>&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5BF9;&#x5176;&#x5B83;&#x53D8;&#x91CF;&#x7684;&#x5F15;&#x7528;&#x3002;</p>
<p><em>Example</em>&#xFF1A;variables2.properties</p>
<pre><code class="lang-properties">USER_HOME=/data/logs
fileName=myApp.log
destination=${USER_HOME}/${fileName}
</code></pre>
<p><em>Example</em>&#xFF1A;variableSubsitution4.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- &#x6CE8;: &#x5B98;&#x7F51;&#x7684;&#x4F8B;&#x5B50;&#x4E0D;&#x662F; resource &#x800C;&#x662F; file --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">property</span> <span class="hljs-attr">resource</span>=<span class="hljs-string">&quot;variables2.properties&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>${destination}<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h4 id="&#x540D;&#x5B57;&#x5D4C;&#x5957;">&#x540D;&#x5B57;&#x5D4C;&#x5957;</h4>
<p>&#x53D8;&#x91CF;&#x7684;&#x540D;&#x5B57;&#x53EF;&#x4EE5;&#x5305;&#x542B;&#x5BF9;&#x5176;&#x5B83;&#x53D8;&#x91CF;&#x7684;&#x5F15;&#x7528;&#x3002;&#x4F8B;&#x5982;&#xFF1A;&#x5982;&#x679C;&#x53D8;&#x91CF; <em>userid=alice</em>&#xFF0C;&#x90A3;&#x4E48; &quot;${${userid}.password}&quot; &#x5C31;&#x662F;&#x5BF9;&#x53D8;&#x91CF;&#x540D;&#x4E3A; &quot;alice.passowrd&quot; &#x7684;&#x5F15;&#x7528;&#x3002;</p>
<h4 id="&#x9ED8;&#x8BA4;&#x503C;&#x5D4C;&#x5957;">&#x9ED8;&#x8BA4;&#x503C;&#x5D4C;&#x5957;</h4>
<p>&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#x53EF;&#x4EE5;&#x5F15;&#x7528;&#x53E6;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x3002;&#x4F8B;&#x5982;&#xFF1A;&#x5047;&#x8BBE;&#x53D8;&#x91CF; &quot;id&quot; &#x6CA1;&#x6709;&#x88AB;&#x5B9A;&#x4E49;&#xFF0C;&#x53D8;&#x91CF; &quot;userid&quot; &#x7684;&#x503C;&#x4E3A; &quot;alice&quot;&#xFF0C;&#x90A3;&#x4E48;&#x8868;&#x8FBE;&#x5F0F; &quot;${id:-${userid}}&quot; &#x7684;&#x503C;&#x4E3A; &quot;alice&quot;&#x3002;</p>
<h3 id="hostname-&#x5C5E;&#x6027;">HOSTNAME &#x5C5E;&#x6027;</h3>
<p><code>HOSTNAME</code> &#x5728;&#x914D;&#x7F6E;&#x671F;&#x95F4;&#x4F1A;&#x88AB;&#x81EA;&#x52A8;&#x5B9A;&#x4E49;&#x4E3A;&#x4E0A;&#x4E0B;&#x6587;&#x8303;&#x56F4;&#x5185;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>${HOSTNAME} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="contextname-&#x5C5E;&#x6027;">CONTEXT_NAME &#x5C5E;&#x6027;</h3>
<p>&#x901A;&#x8FC7;&#x540D;&#x5B57;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x6765;&#xFF0C;<code>CONTEXT_NAME</code> &#x5C5E;&#x6027;&#x5BF9;&#x5E94;&#x5F53;&#x524D;&#x4E0A;&#x4E0B;&#x6587;&#x7684;&#x540D;&#x5B57;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>${CONTEXT_NAME} - %msg%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;debug&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;STDOUT&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="&#x52A8;&#x6001;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;">&#x52A8;&#x6001;&#x5B9A;&#x4E49;&#x5C5E;&#x6027;</h3>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>&lt;define&gt;</code> &#x5143;&#x7D20;&#x52A8;&#x6001;&#x7684;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x3002;&#x8FD9;&#x4E2A;&#x5143;&#x7D20;&#x9700;&#x8981;&#x4E24;&#x4E2A;&#x5F3A;&#x5236;&#x7684;&#x5C5E;&#x6027;&#xFF1A;<em>name</em>&#x3001;<em>class</em>&#x3002;<em>name</em> &#x5C5E;&#x6027;&#x7528;&#x6765;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#x7684;&#x540D;&#x5B57;&#xFF0C;<em>classs</em> &#x5C5E;&#x6027;&#x7528;&#x6765;&#x5F15;&#x7528;&#x5B9E;&#x73B0;&#x4E86; <a href="https://logback.qos.ch/xref/ch/qos/logback/core/spi/PropertyDefiner.html" target="_blank">PropertyDefiner</a> &#x63A5;&#x53E3;&#x7684;&#x7C7B;&#x3002;<code>PropertyDefiner</code> &#x5B9E;&#x4F8B;&#x7684; <code>getPropertyValue()</code> &#x7684;&#x8FD4;&#x56DE;&#x503C;&#x5C31;&#x662F;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x3002;&#x8FD8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <em>scope</em> &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x53D8;&#x91CF;&#x7684;<a href="#&#x4F5C;&#x7528;&#x57DF;">&#x4F5C;&#x7528;&#x57DF;</a>&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">define</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;rootLevel&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;chapters.configuration.PropertyDefiner1&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">shape</span>&gt;</span>round<span class="hljs-tag">&lt;/<span class="hljs-name">shape</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">color</span>&gt;</span>brown<span class="hljs-tag">&lt;/<span class="hljs-name">color</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">size</span>&gt;</span>24<span class="hljs-tag">&lt;/<span class="hljs-name">size</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">define</span>&gt;</span>

  <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;${rootLevel}&quot;</span>/&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>shape&#xFF0C;color&#xFF0C;size &#x90FD;&#x662F; &quot;chapters.configuration.PropertyDefiner1&quot; &#x7684;&#x5C5E;&#x6027;&#x3002;&#x53EA;&#x8981;&#x5728;&#x5B9E;&#x73B0;&#x7C7B;&#x91CC;&#x9762;&#xFF0C;&#x5404;&#x5C5E;&#x6027;&#x6709;&#x5BF9;&#x5E94;&#x7684; set &#x65B9;&#x6CD5;&#xFF0C;logback &#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x7ED9;&#x5404;&#x5C5E;&#x6027;&#x6CE8;&#x5165;&#x5BF9;&#x5E94;&#x7684;&#x503C;&#x3002;</p>
<p>&#x76EE;&#x524D;&#xFF0C;logback &#x5DF2;&#x7ECF;&#x6709;&#x4E86;&#x51E0;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x5B9E;&#x73B0;&#x7C7B;&#xFF1A;</p>
<table>
<thead>
<tr>
<th style="text-align:center">&#x7C7B;&#x540D;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:center"><a href="https://logback.qos.ch/apidocs/ch/qos/logback/core/property/CanonicalHostNamePropertyDefiner.html" target="_blank"><code>CanonicalHostNamePropertyDefiner</code></a></td>
<td style="text-align:left">&#x5C06;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x8BBE;&#x7F6E;&#x4E3A;&#x672C;&#x5730;&#x7684;&#x4E3B;&#x673A;&#x540D;&#x3002;&#x6CE8;&#x610F;&#xFF1A;&#x83B7;&#x53D6;&#x4E3B;&#x673A;&#x540D;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x82B1;&#x8D39;&#x51E0;&#x79D2;&#x7684;&#x65F6;&#x95F4;&#x3002;</td>
</tr>
<tr>
<td style="text-align:center"><a href="https://logback.qos.ch/apidocs/ch/qos/logback/core/property/FileExistsPropertyDefiner.html" target="_blank"><code>FileExistsPropertyDefiner</code></a></td>
<td style="text-align:left">&#x5982;&#x679C;&#x901A;&#x8FC7; <code>path</code> &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x7684;&#x6587;&#x4EF6;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8BBE;&#x7F6E;&#x53D8;&#x91CF;&#x4E3A; &quot;true&quot;&#xFF0C;&#x5426;&#x5219;&#x8BBE;&#x7F6E;&#x4E3A; &quot;false&quot;&#x3002;</td>
</tr>
<tr>
<td style="text-align:center"><a href="https://logback.qos.ch/apidocs/ch/qos/logback/core/property/FileExistsPropertyDefiner.html" target="_blank"><code>ResourceExistsPropertyDefiner</code></a></td>
<td style="text-align:left">&#x5982;&#x679C;&#x901A;&#x8FC7; <code>resource</code> &#x5C5E;&#x6027;&#x6307;&#x5B9A;&#x7684;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x5728;&#x7C7B;&#x8DEF;&#x5F84;&#x4E2D;&#x5B58;&#x5728;&#xFF0C;&#x5219;&#x8BBE;&#x7F6E;&#x53D8;&#x91CF;&#x4E3A; &quot;true&quot;&#xFF0C;&#x5426;&#x5219;&#x8BBE;&#x7F6E;&#x4E3A; &quot;false&quot;&#x3002;</td>
</tr>
</tbody>
</table>
<h3 id="&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6761;&#x4EF6;&#x5904;&#x7406;">&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x7684;&#x6761;&#x4EF6;&#x5904;&#x7406;</h3>
<p>&#x5F00;&#x53D1;&#x8005;&#x901A;&#x5E38;&#x9700;&#x8981;&#x5728;&#x591A;&#x4E2A;&#x73AF;&#x5883;&#x4E2D;&#x5207;&#x6362;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;&#x5F00;&#x53D1;&#xFF0C;&#x6D4B;&#x8BD5;&#x548C;&#x751F;&#x4EA7;&#x3002;&#x8FD9;&#x4E9B;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x6709;&#x5927;&#x91CF;&#x76F8;&#x540C;&#x7684;&#x5730;&#x65B9;&#xFF0C;&#x53EA;&#x6709;&#x5C11;&#x6570;&#x5730;&#x65B9;&#x4E0D;&#x540C;&#x3002;&#x4E3A;&#x4E86;&#x907F;&#x514D;&#x91CD;&#x590D;&#xFF0C;logback &#x5728;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x4E2D;&#x652F;&#x6301;&#x901A;&#x8FC7; <code>&lt;if&gt;</code>&#x3001;<code>&lt;then&gt;</code>&#x3001;<code>&lt;else&gt;</code> &#x5143;&#x7D20;&#x4F5C;&#x4E3A;&#x6761;&#x4EF6;&#x8BED;&#x53E5;&#x6765;&#x533A;&#x5206;&#x4E0D;&#x540C;&#x7684;&#x73AF;&#x5883;&#x3002;&#x6761;&#x4EF6;&#x5904;&#x7406;&#x9700;&#x8981; <a href="https://logback.qos.ch/setup.html#janino" target="_blank">Janino</a> &#x73AF;&#x5883;&#x7684;&#x652F;&#x6301;&#x3002;</p>
<p><em>Example</em>&#xFF1A;</p>
<pre><code class="lang-xml">    <span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">&quot;&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">then</span>&gt;</span>
            ...
        <span class="hljs-tag">&lt;/<span class="hljs-name">then</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">&quot;&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">then</span>&gt;</span>
            ...
        <span class="hljs-tag">&lt;/<span class="hljs-name">then</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">else</span>&gt;</span>
            ...
        <span class="hljs-tag">&lt;/<span class="hljs-name">else</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>
</code></pre>
<p>&#x6761;&#x4EF6;&#x8868;&#x8FBE;&#x5F0F;&#x53EA;&#x80FD;&#x662F;&#x4E0A;&#x4E0B;&#x6587;&#x53D8;&#x91CF;&#x6216;&#x8005;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;&#x3002;&#x56E0;&#x4E3A;&#x503C;&#x662F;&#x901A;&#x8FC7;&#x53C2;&#x6570;&#x4F20;&#x9012;&#x7684;&#xFF0C;<code>property()</code> &#x65B9;&#x6CD5;&#x6216;&#x8005;&#x5176;&#x7B49;&#x4EF7;&#x7684; <code>p()</code> &#x65B9;&#x6CD5;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x3002;&#x4F8B;&#x5982;&#xFF1A;&#x5982;&#x679C;&#x8981;&#x83B7;&#x53D6;&#x53D8;&#x91CF; &quot;k&quot; &#x7684;&#x503C;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>property(&quot;k&quot;)</code> &#x6216;&#x8005; <code>p(&quot;k&quot;)</code> &#x6765;&#x83B7;&#x53D6;&#x3002;&#x5982;&#x679C; &quot;k&quot; &#x6CA1;&#x6709;&#x5B9A;&#x4E49;&#xFF0C;&#x90A3;&#x4E48;&#x65B9;&#x6CD5;&#x5C06;&#x4F1A;&#x8FD4;&#x56DE;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;&#x3002;&#x6240;&#x4EE5;&#x4E0D;&#x9700;&#x8981;&#x53BB;&#x5224;&#x65AD;&#x662F;&#x5426;&#x4E3A; null&#x3002;</p>
<p><code>isDefined()</code> &#x65B9;&#x6CD5;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x5224;&#x65AD;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x88AB;&#x5B9A;&#x4E49;&#x3002;&#x4F8B;&#x5982;&#xFF1A;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>isDefined(&quot;k&quot;)</code> &#x6765;&#x5224;&#x65AD; k &#x662F;&#x5426;&#x5DF2;&#x7ECF;&#x5B9A;&#x4E49;&#x3002;&#x8FD8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>isNull()</code> &#x65B9;&#x6CD5;&#x6765;&#x5224;&#x65AD;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x4E3A; null&#x3002;&#x4F8B;&#x5982;&#xFF1A;<code>isNull(&quot;k&quot;)</code>&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">if</span> <span class="hljs-attr">condition</span>=<span class="hljs-string">&apos;property(&quot;HOSTNAME&quot;).contains(&quot;volong&quot;)&apos;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">then</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;CON&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d %-5level %logger{35} - %msg %n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">root</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;CON&quot;</span> /&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">then</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">if</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;FILE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.FileAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">file</span>&gt;</span>${randomOutputDir}/conditional.log<span class="hljs-tag">&lt;/<span class="hljs-name">file</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>${HOSTNAME} %d %-5level %logger{35} - %msg %n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;ERROR&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;FILE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x6761;&#x4EF6;&#x5904;&#x7406;&#x8BED;&#x53E5;&#x4E0E;&#x5D4C;&#x5957;&#x7684; if-else &#x8BED;&#x53E5;&#x5728; <code>&lt;configuration&gt;</code> &#x5143;&#x7D20;&#x5185;&#x90FD;&#x662F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x7684;&#x3002;&#x4F46;&#x662F; xml &#x7684;&#x8BED;&#x6CD5;&#x975E;&#x5E38;&#x7684;&#x7E41;&#x7410;&#xFF0C;&#x4E0D;&#x9002;&#x5408;&#x4F5C;&#x4E3A;&#x901A;&#x7528;&#x53D8;&#x6210;&#x8BED;&#x8A00;&#x7684;&#x57FA;&#x7840;&#x3002;&#x56E0;&#x6B64;&#xFF0C;&#x4E0D;&#x5EFA;&#x8BAE;&#x4F7F;&#x7528;&#x8FC7;&#x591A;&#x7684;&#x6761;&#x4EF6;&#x8BED;&#x53E5;&#xFF0C;&#x56E0;&#x4E3A;&#x522B;&#x4EBA;&#x770B;&#x4E86;&#x96BE;&#x4EE5;&#x7406;&#x89E3;&#xFF0C;&#x5BF9;&#x4F60;&#x81EA;&#x5DF1;&#x4E5F;&#x662F;&#x5982;&#x6B64;&#x3002;</p>
<h3 id="&#x4ECE;-jndi-&#x4E2D;&#x83B7;&#x53D6;&#x53D8;&#x91CF;">&#x4ECE; JNDI &#x4E2D;&#x83B7;&#x53D6;&#x53D8;&#x91CF;</h3>
<p>&#x5728;&#x67D0;&#x4E9B;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5982;&#x679C;&#x4ECE; JNDI &#x4E2D;&#x83B7;&#x53D6;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x3002;<code>&lt;insertFromJNDI&gt;</code> &#x5143;&#x7D20;&#x80FD;&#x591F;&#x83B7;&#x53D6;&#x5B58;&#x50A8;&#x5728; JNDI &#x4E2D;&#x7684;&#x5143;&#x7D20;&#x5E76;&#x63D2;&#x5165;&#x5230;&#x672C;&#x5730;&#x7684;&#x4E0A;&#x4E0B;&#x6587;&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7; <code>as</code> &#x5C5E;&#x6027;&#x83B7;&#x53D6;&#x5177;&#x4F53;&#x7684;&#x503C;&#x3002;&#x8FD8;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<a href="#&#x4F5C;&#x7528;&#x57DF;">&#x4F5C;&#x7528;&#x57DF;</a>&#x5C06;&#x53D8;&#x91CF;&#x63D2;&#x5165;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x4E2D;&#x3002;</p>
<p><em>Example</em>&#xFF1A;insertFromJNDI.xml</p>
<pre><code class="lang-xml"><span class="hljs-comment">&lt;!-- appName &#x7684;&#x914D;&#x7F6E;&#x5728; web.xml &#x4E2D; 
    &#x4F7F;&#x7528;&#x7684;&#x662F; eclipse &#x7684; jetty &#x63D2;&#x4EF6;&#x8FD0;&#x884C;&#x7684;
    &#x8FD0;&#x884C;&#x65F6;&#x5019;&#x7684;&#x914D;&#x7F6E;&#xFF1A;&#x53F3;&#x952E;&#x70B9;&#x51FB;&#x9879;&#x76EE; -&gt; Run Configurations -&gt; Jetty &#x9009;&#x9879;&#x5361;&#x4E0B;&#x9009;&#x62E9; Show Advanced Options -&gt; &#x9009;&#x4E2D; JNDI Support -&gt; &#x5728;&#x8FD0;&#x884C;&#x5C31;&#x53EF;&#x4EE5;&#x4E86;
--&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">insertFromJNDI</span> <span class="hljs-attr">env-entry-name</span>=<span class="hljs-string">&quot;java:comp/env/appName&quot;</span> <span class="hljs-attr">as</span>=<span class="hljs-string">&quot;appName&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">contextName</span>&gt;</span>${appName}<span class="hljs-tag">&lt;/<span class="hljs-name">contextName</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;CONSOLE&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d %contextName %level %msg %logger{50}%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;CONSOLE&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<h3 id="&#x5F15;&#x5165;&#x6587;&#x4EF6;">&#x5F15;&#x5165;&#x6587;&#x4EF6;</h3>
<p>&#x901A;&#x8FC7; <code>&lt;include&gt;</code> &#x5143;&#x7D20;&#x53EF;&#x4EE5;&#x5F15;&#x5165;&#x5916;&#x90E8;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x3002;</p>
<p><em>Example</em>&#xFF1A;containingConfig.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">include</span> <span class="hljs-attr">file</span>=<span class="hljs-string">&quot;src/main/resources/includedConfig.xml&quot;</span> /&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-name">root</span> <span class="hljs-attr">level</span>=<span class="hljs-string">&quot;DEBUG&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">appender-ref</span> <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;includedConsole&quot;</span> /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">root</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p>&#x76EE;&#x6807;&#x6587;&#x4EF6;&#x5FC5;&#x987B;&#x662F;&#x7531; <code>&lt;included&gt;</code> &#x5143;&#x7D20;&#x5305;&#x88F9;&#x7684;&#x3002;</p>
<p><em>Example</em>&#xFF1A;includedConfig.xml</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">included</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">appender</span> <span class="hljs-attr">name</span>=<span class="hljs-string">&quot;includedConsole&quot;</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.core.ConsoleAppender&quot;</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">encoder</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">pattern</span>&gt;</span>%d - %m%n<span class="hljs-tag">&lt;/<span class="hljs-name">pattern</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">encoder</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">appender</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">included</span>&gt;</span>
</code></pre>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5982;&#x4E0B;&#x51E0;&#x4E2A;&#x5C5E;&#x6027;&#x5F15;&#x5165;&#x6587;&#x4EF6;&#xFF1A;</p>
<ul>
<li><p><strong>&#x901A;&#x8FC7;&#x6587;&#x4EF6;&#x5F15;&#x5165;</strong>&#xFF1A;</p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>file</code> &#x5C5E;&#x6027;&#x5F15;&#x5165;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x3002;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x6216;&#x8005;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x6765;&#x5F15;&#x5165;&#x3002;&#x76F8;&#x5BF9;&#x8DEF;&#x5F84;&#x662F;&#x6307;&#x76F8;&#x5BF9;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x8DEF;&#x5F84;&#x3002;</p>
</li>
<li><p><strong>&#x901A;&#x8FC7;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x5F15;&#x5165;</strong></p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>resource</code> &#x5C5E;&#x6027;&#x6765;&#x5F15;&#x5165;&#x4F4D;&#x4E8E; classpath &#x8DEF;&#x5F84;&#x4E0B;&#x7684;&#x8D44;&#x6E90;&#x6587;&#x4EF6;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">include</span> <span class="hljs-attr">resource</span>=<span class="hljs-string">&quot;includedConfig.xml&quot;</span>/&gt;</span>
</code></pre>
</li>
<li><p><strong>&#x901A;&#x8FC7; url &#x5F15;&#x5165;&#x6587;&#x4EF6;</strong></p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <code>url</code> &#x5C5E;&#x6027;&#x6765;&#x5F15;&#x5165;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">include</span> <span class="hljs-attr">url</span>=<span class="hljs-string">&quot;http://some.host.com/includedConfig.xml&quot;</span>/&gt;</span>
</code></pre>
</li>
</ul>
<p>&#x5982;&#x679C; logback &#x6CA1;&#x6709;&#x901A;&#x8FC7; <code>include</code> &#x5143;&#x7D20;&#x627E;&#x5230;&#x6307;&#x5B9A;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#xFF0C;&#x4F1A;&#x5728;&#x63A7;&#x5236;&#x53F0;&#x6253;&#x5370;&#x51FA;&#x5185;&#x90E8;&#x72B6;&#x6001;&#x4FE1;&#x606F;&#x3002;&#x5982;&#x679C;&#x5F15;&#x5165;&#x7684;&#x5916;&#x90E8;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E; <code>optional=true</code>&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">include</span> <span class="hljs-attr">optional</span>=<span class="hljs-string">&quot;true&quot;</span> <span class="hljs-attr">....</span>/&gt;</span>
</code></pre>
<h2 id="&#x6DFB;&#x52A0;&#x4E0A;&#x4E0B;&#x6587;&#x76D1;&#x542C;&#x5668;">&#x6DFB;&#x52A0;&#x4E0A;&#x4E0B;&#x6587;&#x76D1;&#x542C;&#x5668;</h2>
<p><a href="https://logback.qos.ch/xref/ch/qos/logback/classic/spi/LoggerContextListener.html" target="_blank">LoggerContextListener</a> &#x63A5;&#x53E3;&#x7684;&#x5B9E;&#x4F8B;&#x76D1;&#x542C;&#x4E0A;&#x4E0B;&#x6587;&#x751F;&#x547D;&#x5468;&#x671F;&#x5185;&#x7684;&#x4E8B;&#x4EF6;&#x3002;</p>
<p><code>JMXConfigurator</code> &#x662F; <code>LoggerContextListener</code> &#x63A5;&#x53E3;&#x7684;&#x4E00;&#x4E2A;&#x5B9E;&#x73B0;&#x3002;</p>
<h3 id="&#x66F4;&#x6539;&#x4F20;&#x64AD;&#x7EA7;&#x522B;">&#x66F4;&#x6539;&#x4F20;&#x64AD;&#x7EA7;&#x522B;</h3>
<p>&#x5728; 0.9.25 &#x7248;&#x672C;&#xFF0C;logback-classic &#x901A;&#x8FC7; <code>LoggerContextListener</code> &#x7684;&#x5B9E;&#x73B0;&#x7C7B; <a href="https://logback.qos.ch/xref/ch/qos/logback/classic/jul/LevelChangePropagator.html" target="_blank">LevelChangePropagator</a> &#x6765;&#x66F4;&#x6539; logback-classic &#x4E2D;&#x7684; logger &#x4F20;&#x64AD;&#x5230; java.util.logging &#x4E2D;&#x7684;&#x65E5;&#x5FD7;&#x7EA7;&#x522B;&#x3002;&#x8FD9;&#x4E9B;&#x4F20;&#x64AD;&#x6D88;&#x9664;&#x4E86;&#x7981;&#x6B62;&#x6253;&#x5370;&#x65E5;&#x5FD7;&#x65F6;&#x7684;&#x6027;&#x80FD;&#x635F;&#x8017;&#x3002;<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/logging/LogRecord.html?is-external=true" target="_blank">LogRecord</a> &#x5B9E;&#x4F8B;&#x4EC5;&#x4EC5;&#x4F1A;&#x5728;&#x5141;&#x8BB8;&#x6253;&#x5370;&#x65E5;&#x5FD7;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x901A;&#x8FC7; SFL4J &#x4F20;&#x64AD;&#x5230; logback&#x3002;</p>
<p>&#x914D;&#x7F6E; <code>LevelChangePropagator</code>&#xFF1A;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">contextListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.jul.LevelChangePropagator&quot;</span>/&gt;</span>
  .... 
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>
<p><code>resetJUL</code> &#x5C5E;&#x6027;&#x4F1A;&#x91CD;&#x7F6E; j.u.l &#x4E2D;&#x7684;&#x6240;&#x6709; logger &#x7684;&#x7B49;&#x7EA7;&#x914D;&#x7F6E;&#x3002;&#x4F46;&#x662F;&#x4E4B;&#x524D;&#x914D;&#x7F6E;&#x7684;&#x5C06;&#x4E0D;&#x4F1A;&#x53D7;&#x5230;&#x5F71;&#x54CD;&#x3002;</p>
<pre><code class="lang-xml"><span class="hljs-tag">&lt;<span class="hljs-name">configuration</span> <span class="hljs-attr">debug</span>=<span class="hljs-string">&quot;true&quot;</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">contextListener</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;ch.qos.logback.classic.jul.LevelChangePropagator&quot;</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">resetJUL</span>&gt;</span>true<span class="hljs-tag">&lt;/<span class="hljs-name">resetJUL</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">contextListener</span>&gt;</span>
  ....
<span class="hljs-tag">&lt;/<span class="hljs-name">configuration</span>&gt;</span>
</code></pre>



                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="02第二章架构.html" class="navigation navigation-prev " aria-label="Previous page: 第二章：架构">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="04第四章Appenders.html" class="navigation navigation-next " aria-label="Next page: 第四章：Appenders">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"第三章：logback 的配置","level":"1.4","depth":1,"next":{"title":"第四章：Appenders","level":"1.5","depth":1,"path":"04第四章Appenders.md","ref":"04第四章Appenders.md","articles":[]},"previous":{"title":"第二章：架构","level":"1.3","depth":1,"path":"02第二章架构.md","ref":"02第二章架构.md","articles":[]},"dir":"ltr"},"config":{"plugins":["add-js-css","myseo"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"add-js-css":{"js":["./lib/site.js"]},"myseo":{"description":"logback中文网包含了logback中文文档，最新资讯，应用案例等。logback 继承自 log4j，它建立在有十年工业经验的日志系统之上。它比其它所有的日志系统更快并且更小，包含了许多独特并且有用的特性。","keywords":"logback中文文档, logback api文档, logback log4j,springboot logback,logback日志类型","titlePrefix":"logback中文网|"},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","keywords":"","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"logback中文手册","gitbook":"*","description":""},"file":{"path":"03第三章logback的配置.md","mtime":"2019-02-23T06:45:23.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-24T03:19:05.191Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-add-js-css/fda70cfc36440304bb976a11f47eb151-site.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

